Skip to content

Commit 11f9d06

Browse files
authored
feat: add solutions to lc problem: No.2117 (#1870)
1 parent 9706e12 commit 11f9d06

File tree

26 files changed

+591
-38
lines changed

26 files changed

+591
-38
lines changed

solution/0100-0199/0175.Combine Two Tables/README.md

+3-2
Original file line numberDiff line numberDiff line change
@@ -96,15 +96,16 @@ FROM
9696
LEFT JOIN Address USING (personId);
9797
```
9898

99-
```pandas
99+
### **Pandas**
100+
101+
```python
100102
import pandas as pd
101103

102104

103105
def combine_two_tables(person: pd.DataFrame, address: pd.DataFrame) -> pd.DataFrame:
104106
return pd.merge(left=person, right=address, how="left", on="personId")[
105107
["firstName", "lastName", "city", "state"]
106108
]
107-
108109
```
109110

110111
<!-- tabs:end -->

solution/0100-0199/0175.Combine Two Tables/README_EN.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,9 @@ FROM
9292
LEFT JOIN Address USING (personId);
9393
```
9494

95-
```pandas
95+
### **Pandas**
96+
97+
```python
9698
import pandas as pd
9799

98100

solution/0100-0199/0176.Second Highest Salary/README.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,8 @@ WITH T AS (SELECT salary, DENSE_RANK() OVER (ORDER BY salary DESC) AS rk FROM Em
113113
SELECT (SELECT DISTINCT salary FROM T WHERE rk = 2) AS SecondHighestSalary;
114114
```
115115

116+
### **Pandas**
117+
116118
```python
117119
import pandas as pd
118120

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

136138
return result_df
137-
138139
```
139140

140141
<!-- tabs:end -->

solution/0100-0199/0176.Second Highest Salary/README_EN.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,8 @@ WITH T AS (SELECT salary, DENSE_RANK() OVER (ORDER BY salary DESC) AS rk FROM Em
9898
SELECT (SELECT DISTINCT salary FROM T WHERE rk = 2) AS SecondHighestSalary;
9999
```
100100

101+
### **Pandas**
102+
101103
```python
102104
import pandas as pd
103105

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

121123
return result_df
122-
123124
```
124125

125126
<!-- tabs:end -->

solution/0100-0199/0177.Nth Highest Salary/README.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,8 @@ BEGIN
9494
END
9595
```
9696

97+
### **Pandas**
98+
9799
```python
98100
import pandas as pd
99101

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

111112
<!-- tabs:end -->

solution/0100-0199/0177.Nth Highest Salary/README_EN.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,8 @@ BEGIN
8686
END
8787
```
8888

89+
### **Pandas**
90+
8991
```python
9092
import pandas as pd
9193

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

103104
<!-- tabs:end -->

solution/0100-0199/0178.Rank Scores/README.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,8 @@ FROM
122122
) s;
123123
```
124124

125+
### **Pandas**
126+
125127
```python
126128
import pandas as pd
127129

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

136138
return result_df
137-
138139
```
139140

140141
<!-- tabs:end -->

solution/0100-0199/0178.Rank Scores/README_EN.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,8 @@ FROM
113113
) s;
114114
```
115115

116+
### **Pandas**
117+
116118
```python
117119
import pandas as pd
118120

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

127129
return result_df
128-
129130
```
130131

131132
<!-- tabs:end -->

solution/0100-0199/0180.Consecutive Numbers/README.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,8 @@ GROUP BY p
116116
HAVING COUNT(1) >= 3;
117117
```
118118

119+
### **Pandas**
120+
119121
```python
120122
import pandas as pd
121123

@@ -130,7 +132,6 @@ def consecutive_numbers(logs: pd.DataFrame) -> pd.DataFrame:
130132
.drop_duplicates()
131133
.rename(columns={"num": "ConsecutiveNums"})
132134
)
133-
134135
```
135136

136137
<!-- tabs:end -->

solution/0100-0199/0180.Consecutive Numbers/README_EN.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,8 @@ GROUP BY p
112112
HAVING COUNT(1) >= 3;
113113
```
114114

115+
### **Pandas**
116+
115117
```python
116118
import pandas as pd
117119

@@ -126,7 +128,6 @@ def consecutive_numbers(logs: pd.DataFrame) -> pd.DataFrame:
126128
.drop_duplicates()
127129
.rename(columns={"num": "ConsecutiveNums"})
128130
)
129-
130131
```
131132

132133
<!-- tabs:end -->

solution/0100-0199/0181.Employees Earning More Than Their Managers/README.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,8 @@ FROM
8181
WHERE e1.salary > e2.salary;
8282
```
8383

84+
### **Pandas**
85+
8486
```python
8587
import pandas as pd
8688

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

9294
return pd.DataFrame({"Employee": emp})
93-
9495
```
9596

9697
<!-- tabs:end -->

solution/0100-0199/0181.Employees Earning More Than Their Managers/README_EN.md

+2
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,8 @@ FROM
7777
WHERE e1.salary > e2.salary;
7878
```
7979

80+
### **Pandas**
81+
8082
```python
8183
import pandas as pd
8284

solution/0100-0199/0182.Duplicate Emails/README.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,8 @@ FROM
8383
WHERE p1.id != p2.id AND p1.email = p2.email;
8484
```
8585

86+
### **Pandas**
87+
8688
```python
8789
import pandas as pd
8890

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

9597
return results.drop_duplicates()
96-
9798
```
9899

99100
<!-- tabs:end -->

solution/0100-0199/0182.Duplicate Emails/README_EN.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,8 @@ FROM
7777
WHERE p1.id != p2.id AND p1.email = p2.email;
7878
```
7979

80+
### **Pandas**
81+
8082
```python
8183
import pandas as pd
8284

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

8991
return results.drop_duplicates()
90-
9192
```
9293

9394
<!-- tabs:end -->

solution/0100-0199/0183.Customers Who Never Order/README.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,8 @@ FROM
105105
WHERE o.id IS NULL;
106106
```
107107

108+
### **Pandas**
109+
108110
```python
109111
import pandas as pd
110112

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

119121
return df
120-
121122
```
122123

123124
<!-- tabs:end -->

solution/0100-0199/0183.Customers Who Never Order/README_EN.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,8 @@ FROM
105105
WHERE o.id IS NULL;
106106
```
107107

108+
### **Pandas**
109+
108110
```python
109111
import pandas as pd
110112

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

119121
return df
120-
121122
```
122123

123124
<!-- tabs:end -->

0 commit comments

Comments
 (0)