Skip to content

Commit 14dd5d8

Browse files
authored
feat: add solutions to lc problems (doocs#1130)
* No.1910.Remove All Occurrences of a Substring * No.1934.Confirmation Rate * No.1978.Employees Whose Manager Left the Company * No.2026.Low-Quality Problems * No.2175.The Change in Global Rankings * No.2199.Finding the Topic of Each Post * No.2230.The Users That Are Eligible for Discount * No.2480.Form a Chemical Bond
1 parent 7a6e3ad commit 14dd5d8

File tree

29 files changed

+331
-16
lines changed

29 files changed

+331
-16
lines changed

.prettierrc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,10 @@
3232
"solution/1500-1599/1555.Bank Account Summary/Solution.sql",
3333
"solution/1600-1699/1667.Fix Names in a Table/Solution.sql",
3434
"solution/1700-1799/1777.Product's Price for Each Store/Solution.sql",
35+
"solution/1900-1999/1934.Confirmation Rate/Solution.sql",
3536
"solution/1900-1999/1972.First and Last Call On the Same Day/Solution.sql",
3637
"solution/2000-2099/2066.Account Balance/Solution.sql",
38+
"solution/2200-2299/2230.The Users That Are Eligible for Discount/Solution.sql",
3739
"solution/2600-2699/2686.Immediate Food Delivery III/Solution.sql",
3840
"solution/2700-2799/2752.Customers with Maximum Number of Transactions on Consecutive Days/Solution.sql"
3941
],

solution/1900-1999/1910.Remove All Occurrences of a Substring/README.md

Lines changed: 55 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,22 +55,76 @@
5555

5656
<!-- 这里可写通用的实现逻辑 -->
5757

58+
**方法一:暴力替换**
59+
60+
我们循环判断 $s$ 中是否存在字符串 $part$,是则进行一次替换,继续循环此操作,直至 $s$ 中不存在字符串 $part$,返回此时的 $s$ 作为答案字符串。
61+
62+
时间复杂度 $O(n^2 + n \times m)$,空间复杂度 $O(n + m)$。其中 $n$ 和 $m$ 分别是字符串 $s$ 和字符串 $part$ 的长度。
63+
5864
<!-- tabs:start -->
5965

6066
### **Python3**
6167

6268
<!-- 这里可写当前语言的特殊实现逻辑 -->
6369

6470
```python
65-
71+
class Solution:
72+
def removeOccurrences(self, s: str, part: str) -> str:
73+
while part in s:
74+
s = s.replace(part, '', 1)
75+
return s
6676
```
6777

6878
### **Java**
6979

7080
<!-- 这里可写当前语言的特殊实现逻辑 -->
7181

7282
```java
83+
class Solution {
84+
public String removeOccurrences(String s, String part) {
85+
while (s.contains(part)) {
86+
s = s.replaceFirst(part, "");
87+
}
88+
return s;
89+
}
90+
}
91+
```
92+
93+
### **C++**
94+
95+
```cpp
96+
class Solution {
97+
public:
98+
string removeOccurrences(string s, string part) {
99+
int m = part.size();
100+
while (s.find(part) != -1) {
101+
s = s.erase(s.find(part), m);
102+
}
103+
return s;
104+
}
105+
};
106+
```
107+
108+
### **Go**
109+
110+
```go
111+
func removeOccurrences(s string, part string) string {
112+
for strings.Contains(s, part) {
113+
s = strings.Replace(s, part, "", 1)
114+
}
115+
return s
116+
}
117+
```
118+
119+
### **TypeScript**
73120

121+
```ts
122+
function removeOccurrences(s: string, part: string): string {
123+
while (s.includes(part)) {
124+
s = s.replace(part, '');
125+
}
126+
return s;
127+
}
74128
```
75129

76130
### **...**

solution/1900-1999/1910.Remove All Occurrences of a Substring/README_EN.md

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,13 +56,61 @@ Now s has no occurrences of &quot;xy&quot;.
5656
### **Python3**
5757

5858
```python
59-
59+
class Solution:
60+
def removeOccurrences(self, s: str, part: str) -> str:
61+
while part in s:
62+
s = s.replace(part, '', 1)
63+
return s
6064
```
6165

6266
### **Java**
6367

6468
```java
69+
class Solution {
70+
public String removeOccurrences(String s, String part) {
71+
while (s.contains(part)) {
72+
s = s.replaceFirst(part, "");
73+
}
74+
return s;
75+
}
76+
}
77+
```
78+
79+
### **C++**
80+
81+
```cpp
82+
class Solution {
83+
public:
84+
string removeOccurrences(string s, string part) {
85+
int m = part.size();
86+
while (s.find(part) != -1) {
87+
s = s.erase(s.find(part), m);
88+
}
89+
return s;
90+
}
91+
};
92+
```
93+
94+
### **Go**
95+
96+
```go
97+
func removeOccurrences(s string, part string) string {
98+
for strings.Contains(s, part) {
99+
s = strings.Replace(s, part, "", 1)
100+
}
101+
return s
102+
}
103+
```
104+
105+
### **TypeScript**
65106

107+
```ts
108+
function removeOccurrences(s: string, part: string): string {
109+
while (s.includes(part)) {
110+
s = s.replace(part, '');
111+
}
112+
return s;
113+
}
66114
```
67115

68116
### **...**
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
class Solution {
2+
public:
3+
string removeOccurrences(string s, string part) {
4+
int m = part.size();
5+
while (s.find(part) != -1) {
6+
s = s.erase(s.find(part), m);
7+
}
8+
return s;
9+
}
10+
};
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
func removeOccurrences(s string, part string) string {
2+
for strings.Contains(s, part) {
3+
s = strings.Replace(s, part, "", 1)
4+
}
5+
return s
6+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
class Solution {
2+
public String removeOccurrences(String s, String part) {
3+
while (s.contains(part)) {
4+
s = s.replaceFirst(part, "");
5+
}
6+
return s;
7+
}
8+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
class Solution:
2+
def removeOccurrences(self, s: str, part: str) -> str:
3+
while part in s:
4+
s = s.replace(part, '', 1)
5+
return s
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
function removeOccurrences(s: string, part: string): string {
2+
while (s.includes(part)) {
3+
s = s.replace(part, '');
4+
}
5+
return s;
6+
}

solution/1900-1999/1934.Confirmation Rate/README.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,17 @@ Confirmations 表:
9898
<!-- 这里可写当前语言的特殊实现逻辑 -->
9999

100100
```sql
101-
101+
# Write your MySQL query statement below
102+
SELECT
103+
user_id,
104+
round(
105+
sum(if(action = 'confirmed', 1, 0)) / count(1),
106+
2
107+
) AS confirmation_rate
108+
FROM
109+
Signups
110+
LEFT JOIN Confirmations USING (user_id)
111+
GROUP BY user_id;
102112
```
103113

104114
<!-- tabs:end -->

solution/1900-1999/1934.Confirmation Rate/README_EN.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,17 @@ User 2 made 2 requests where one was confirmed and the other timed out. The conf
9494
### **SQL**
9595

9696
```sql
97-
97+
# Write your MySQL query statement below
98+
SELECT
99+
user_id,
100+
round(
101+
sum(if(action = 'confirmed', 1, 0)) / count(1),
102+
2
103+
) AS confirmation_rate
104+
FROM
105+
Signups
106+
LEFT JOIN Confirmations USING (user_id)
107+
GROUP BY user_id;
98108
```
99109

100110
<!-- tabs:end -->

0 commit comments

Comments
 (0)