|
| 1 | +Here’s a well-structured `README.md` for **LeetCode 1517 - Find Users With Valid E-Mails**, formatted for a GitHub repository: |
| 2 | + |
| 3 | +```md |
| 4 | +# 📩 Find Users With Valid E-Mails - LeetCode 1517 |
| 5 | + |
| 6 | +## 📌 Problem Statement |
| 7 | +You are given a table **Users** that contains user registration details, including their emails. Some of these emails may be **invalid**. |
| 8 | + |
| 9 | +A valid email: |
| 10 | +- Has a **prefix name** and a **domain**. |
| 11 | +- The prefix: |
| 12 | + - **Must start with a letter** (uppercase or lowercase). |
| 13 | + - Can contain **letters**, **digits**, **underscore (`_`)**, **period (`.`)**, and/or **dash (`-`)**. |
| 14 | +- The domain must be **"@leetcode.com"**. |
| 15 | + |
| 16 | +Your task is to **find users with valid emails**. |
| 17 | + |
| 18 | +--- |
| 19 | + |
| 20 | +## 📊 Table Structure |
| 21 | + |
| 22 | +### **Users Table** |
| 23 | +| Column Name | Type | |
| 24 | +| ----------- | ------- | |
| 25 | +| user_id | int | |
| 26 | +| name | varchar | |
| 27 | +| mail | varchar | |
| 28 | + |
| 29 | +- `user_id` is the **primary key**. |
| 30 | + |
| 31 | +--- |
| 32 | + |
| 33 | +## 📊 Example 1: |
| 34 | + |
| 35 | +### **Input:** |
| 36 | +#### **Users Table** |
| 37 | +| user_id | name | mail | |
| 38 | +| ------- | --------- | ----------------------- | |
| 39 | +| 1 | Winston | winston@leetcode.com | |
| 40 | +| 2 | Jonathan | jonathanisgreat | |
| 41 | +| 3 | Annabelle | bella-@leetcode.com | |
| 42 | +| 4 | Sally | sally.come@leetcode.com | |
| 43 | +| 5 | Marwan | quarz#2020@leetcode.com | |
| 44 | +| 6 | David | david69@gmail.com | |
| 45 | +| 7 | Shapiro | .shapo@leetcode.com | |
| 46 | + |
| 47 | +### **Output:** |
| 48 | +| user_id | name | mail | |
| 49 | +| ------- | --------- | ----------------------- | |
| 50 | +| 1 | Winston | winston@leetcode.com | |
| 51 | +| 3 | Annabelle | bella-@leetcode.com | |
| 52 | +| 4 | Sally | sally.come@leetcode.com | |
| 53 | + |
| 54 | +### **Explanation:** |
| 55 | +- ✅ **Valid emails:** |
| 56 | + - `winston@leetcode.com` ✅ (Starts with a letter, correct domain) |
| 57 | + - `bella-@leetcode.com` ✅ (Starts with a letter, correct domain) |
| 58 | + - `sally.come@leetcode.com` ✅ (Starts with a letter, correct domain) |
| 59 | +- ❌ **Invalid emails:** |
| 60 | + - `jonathanisgreat` ❌ (No domain) |
| 61 | + - `quarz#2020@leetcode.com` ❌ (Contains `#`, which is not allowed) |
| 62 | + - `david69@gmail.com` ❌ (Wrong domain) |
| 63 | + - `.shapo@leetcode.com` ❌ (Starts with a period `.`) |
| 64 | + |
| 65 | +--- |
| 66 | + |
| 67 | +## 🖥 SQL Solution |
| 68 | + |
| 69 | +### ✅ **Using `REGEXP_LIKE` (MySQL)** |
| 70 | +#### **Explanation:** |
| 71 | +- Use `REGEXP_LIKE(mail, '^[A-Za-z]+[A-Za-z0-9_.-]*@leetcode\\.com$')` |
| 72 | + - `^` → Start of string. |
| 73 | + - `[A-Za-z]+` → First character **must** be a **letter**. |
| 74 | + - `[A-Za-z0-9_.-]*` → Rest can be **letters, numbers, `_`, `.`, or `-`**. |
| 75 | + - `@leetcode\\.com$` → Must end with `"@leetcode.com"`. |
| 76 | + |
| 77 | +```sql |
| 78 | +SELECT * |
| 79 | +FROM Users |
| 80 | +WHERE REGEXP_LIKE(mail, '^[A-Za-z]+[A-Za-z0-9_.-]*@leetcode\\.com$'); |
| 81 | +``` |
| 82 | + |
| 83 | +--- |
| 84 | + |
| 85 | +## 📁 File Structure |
| 86 | +``` |
| 87 | +📂 Find-Users-With-Valid-Emails |
| 88 | +│── 📜 README.md |
| 89 | +│── 📜 solution.sql |
| 90 | +│── 📜 test_cases.sql |
| 91 | +``` |
| 92 | + |
| 93 | +--- |
| 94 | + |
| 95 | +## 🔗 Useful Links |
| 96 | +- 📖 [LeetCode Problem](https://leetcode.com/problems/find-users-with-valid-e-mails/) |
| 97 | +- 🔍 [MySQL REGEXP_LIKE Documentation](https://dev.mysql.com/doc/refman/8.0/en/regexp.html) |
| 98 | +- 📝 [SQL Regular Expressions Cheatsheet](https://www.w3schools.com/sql/sql_regex.asp) |
| 99 | +``` |
| 100 | +
|
| 101 | +### Features of this `README.md`: |
| 102 | +✅ **Clear problem statement with tables** |
| 103 | +✅ **Example with detailed explanation** |
| 104 | +✅ **SQL solution breakdown** |
| 105 | +✅ **File structure for easy organization** |
| 106 | +✅ **Helpful links for further learning** |
| 107 | +
|
| 108 | +Would you like any modifications? 🚀 |
0 commit comments