Skip to content

feat: add solutions to lc problem: No.2117 #1870

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions solution/0100-0199/0175.Combine Two Tables/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,15 +96,16 @@ FROM
LEFT JOIN Address USING (personId);
```

```pandas
### **Pandas**

```python
import pandas as pd


def combine_two_tables(person: pd.DataFrame, address: pd.DataFrame) -> pd.DataFrame:
return pd.merge(left=person, right=address, how="left", on="personId")[
["firstName", "lastName", "city", "state"]
]

```

<!-- tabs:end -->
4 changes: 3 additions & 1 deletion solution/0100-0199/0175.Combine Two Tables/README_EN.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,9 @@ FROM
LEFT JOIN Address USING (personId);
```

```pandas
### **Pandas**

```python
import pandas as pd


Expand Down
3 changes: 2 additions & 1 deletion solution/0100-0199/0176.Second Highest Salary/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,8 @@ WITH T AS (SELECT salary, DENSE_RANK() OVER (ORDER BY salary DESC) AS rk FROM Em
SELECT (SELECT DISTINCT salary FROM T WHERE rk = 2) AS SecondHighestSalary;
```

### **Pandas**

```python
import pandas as pd

Expand All @@ -134,7 +136,6 @@ def second_highest_salary(employee: pd.DataFrame) -> pd.DataFrame:
result_df = pd.DataFrame({"SecondHighestSalary": [second_highest]})

return result_df

```

<!-- tabs:end -->
3 changes: 2 additions & 1 deletion solution/0100-0199/0176.Second Highest Salary/README_EN.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,8 @@ WITH T AS (SELECT salary, DENSE_RANK() OVER (ORDER BY salary DESC) AS rk FROM Em
SELECT (SELECT DISTINCT salary FROM T WHERE rk = 2) AS SecondHighestSalary;
```

### **Pandas**

```python
import pandas as pd

Expand All @@ -119,7 +121,6 @@ def second_highest_salary(employee: pd.DataFrame) -> pd.DataFrame:
result_df = pd.DataFrame({"SecondHighestSalary": [second_highest]})

return result_df

```

<!-- tabs:end -->
3 changes: 2 additions & 1 deletion solution/0100-0199/0177.Nth Highest Salary/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@ BEGIN
END
```

### **Pandas**

```python
import pandas as pd

Expand All @@ -105,7 +107,6 @@ def nth_highest_salary(employee: pd.DataFrame, N: int) -> pd.DataFrame:
else:
salary = sorted(unique_salaries, reverse=True)[N - 1]
return pd.DataFrame([salary], columns=[f"getNthHighestSalary({N})"])

```

<!-- tabs:end -->
3 changes: 2 additions & 1 deletion solution/0100-0199/0177.Nth Highest Salary/README_EN.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ BEGIN
END
```

### **Pandas**

```python
import pandas as pd

Expand All @@ -97,7 +99,6 @@ def nth_highest_salary(employee: pd.DataFrame, N: int) -> pd.DataFrame:
else:
salary = sorted(unique_salaries, reverse=True)[N - 1]
return pd.DataFrame([salary], columns=[f"getNthHighestSalary({N})"])

```

<!-- tabs:end -->
3 changes: 2 additions & 1 deletion solution/0100-0199/0178.Rank Scores/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,8 @@ FROM
) s;
```

### **Pandas**

```python
import pandas as pd

Expand All @@ -134,7 +136,6 @@ def order_scores(scores: pd.DataFrame) -> pd.DataFrame:
result_df = scores.drop("id", axis=1).sort_values(by="score", ascending=False)

return result_df

```

<!-- tabs:end -->
3 changes: 2 additions & 1 deletion solution/0100-0199/0178.Rank Scores/README_EN.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,8 @@ FROM
) s;
```

### **Pandas**

```python
import pandas as pd

Expand All @@ -125,7 +127,6 @@ def order_scores(scores: pd.DataFrame) -> pd.DataFrame:
result_df = scores.drop("id", axis=1).sort_values(by="score", ascending=False)

return result_df

```

<!-- tabs:end -->
3 changes: 2 additions & 1 deletion solution/0100-0199/0180.Consecutive Numbers/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,8 @@ GROUP BY p
HAVING COUNT(1) >= 3;
```

### **Pandas**

```python
import pandas as pd

Expand All @@ -130,7 +132,6 @@ def consecutive_numbers(logs: pd.DataFrame) -> pd.DataFrame:
.drop_duplicates()
.rename(columns={"num": "ConsecutiveNums"})
)

```

<!-- tabs:end -->
3 changes: 2 additions & 1 deletion solution/0100-0199/0180.Consecutive Numbers/README_EN.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,8 @@ GROUP BY p
HAVING COUNT(1) >= 3;
```

### **Pandas**

```python
import pandas as pd

Expand All @@ -126,7 +128,6 @@ def consecutive_numbers(logs: pd.DataFrame) -> pd.DataFrame:
.drop_duplicates()
.rename(columns={"num": "ConsecutiveNums"})
)

```

<!-- tabs:end -->
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ FROM
WHERE e1.salary > e2.salary;
```

### **Pandas**

```python
import pandas as pd

Expand All @@ -90,7 +92,6 @@ def find_employees(employee: pd.DataFrame) -> pd.DataFrame:
emp = df[df["salary_x"] > df["salary_y"]]["name_x"]

return pd.DataFrame({"Employee": emp})

```

<!-- tabs:end -->
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ FROM
WHERE e1.salary > e2.salary;
```

### **Pandas**

```python
import pandas as pd

Expand Down
3 changes: 2 additions & 1 deletion solution/0100-0199/0182.Duplicate Emails/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ FROM
WHERE p1.id != p2.id AND p1.email = p2.email;
```

### **Pandas**

```python
import pandas as pd

Expand All @@ -93,7 +95,6 @@ def duplicate_emails(person: pd.DataFrame) -> pd.DataFrame:
results = person.loc[person.duplicated(subset=["email"]), ["email"]]

return results.drop_duplicates()

```

<!-- tabs:end -->
3 changes: 2 additions & 1 deletion solution/0100-0199/0182.Duplicate Emails/README_EN.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ FROM
WHERE p1.id != p2.id AND p1.email = p2.email;
```

### **Pandas**

```python
import pandas as pd

Expand All @@ -87,7 +89,6 @@ def duplicate_emails(person: pd.DataFrame) -> pd.DataFrame:
results = person.loc[person.duplicated(subset=["email"]), ["email"]]

return results.drop_duplicates()

```

<!-- tabs:end -->
3 changes: 2 additions & 1 deletion solution/0100-0199/0183.Customers Who Never Order/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,8 @@ FROM
WHERE o.id IS NULL;
```

### **Pandas**

```python
import pandas as pd

Expand All @@ -117,7 +119,6 @@ def find_customers(customers: pd.DataFrame, orders: pd.DataFrame) -> pd.DataFram
df = df[["name"]].rename(columns={"name": "Customers"})

return df

```

<!-- tabs:end -->
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,8 @@ FROM
WHERE o.id IS NULL;
```

### **Pandas**

```python
import pandas as pd

Expand All @@ -117,7 +119,6 @@ def find_customers(customers: pd.DataFrame, orders: pd.DataFrame) -> pd.DataFram
df = df[["name"]].rename(columns={"name": "Customers"})

return df

```

<!-- tabs:end -->
Loading