Skip to content

Commit 8811c2f

Browse files
committed
feat: update lc problems
1 parent 01e0909 commit 8811c2f

File tree

9 files changed

+61
-22
lines changed

9 files changed

+61
-22
lines changed

solution/0300-0399/0367.Valid Perfect Square/README_EN.md

+17-6
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,34 @@
44

55
## Description
66

7-
<p>Given a <strong>positive</strong> integer <i>num</i>, write a function which returns True if <i>num</i> is a perfect square else False.</p>
7+
<p>Given a positive integer num, return <code>true</code> <em>if</em> <code>num</code> <em>is a perfect square or</em> <code>false</code> <em>otherwise</em>.</p>
88

9-
<p><b>Follow up:</b> <b>Do not</b> use any built-in library function such as <code>sqrt</code>.</p>
9+
<p>A <strong>perfect square</strong> is an integer that is the square of an integer. In other words, it is the product of some integer with itself.</p>
10+
11+
<p>You must not use any built-in library function, such as <code>sqrt</code>.</p>
1012

1113
<p>&nbsp;</p>
1214
<p><strong class="example">Example 1:</strong></p>
13-
<pre><strong>Input:</strong> num = 16
15+
16+
<pre>
17+
<strong>Input:</strong> num = 16
1418
<strong>Output:</strong> true
15-
</pre><p><strong class="example">Example 2:</strong></p>
16-
<pre><strong>Input:</strong> num = 14
19+
<strong>Explanation:</strong> We return true because 4 * 4 = 16 and 4 is an integer.
20+
</pre>
21+
22+
<p><strong class="example">Example 2:</strong></p>
23+
24+
<pre>
25+
<strong>Input:</strong> num = 14
1726
<strong>Output:</strong> false
27+
<strong>Explanation:</strong> We return false because 3.742 * 3.742 = 14 and 3.742 is not an integer.
1828
</pre>
29+
1930
<p>&nbsp;</p>
2031
<p><strong>Constraints:</strong></p>
2132

2233
<ul>
23-
<li><code>1 &lt;= num &lt;= 2^31 - 1</code></li>
34+
<li><code>1 &lt;= num &lt;= 2<sup>31</sup> - 1</code></li>
2435
</ul>
2536

2637
## Solutions

solution/0300-0399/0395.Longest Substring with At Least K Repeating Characters/README_EN.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ class Solution:
6060
ans = max(ans, t)
6161
i = j
6262
return ans
63-
63+
6464
return dfs(0, len(s) - 1)
6565
```
6666

solution/0600-0699/0635.Design Log Storage System/README_EN.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -100,11 +100,11 @@ class LogSystem {
100100
d.put("Minute", 16);
101101
d.put("Second", 19);
102102
}
103-
103+
104104
public void put(int id, String timestamp) {
105105
logs.add(new Log(id, timestamp));
106106
}
107-
107+
108108
public List<Integer> retrieve(String start, String end, String granularity) {
109109
List<Integer> ans = new ArrayList<>();
110110
int i = d.get(granularity);
@@ -151,11 +151,11 @@ public:
151151
d["Minute"] = 16;
152152
d["Second"] = 19;
153153
}
154-
154+
155155
void put(int id, string timestamp) {
156156
logs.push_back({id, timestamp});
157157
}
158-
158+
159159
vector<int> retrieve(string start, string end, string granularity) {
160160
vector<int> ans;
161161
int i = d[granularity];

solution/1700-1799/1759.Count Number of Homogenous Substrings/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ int countHomogenous(char *s) {
258258
for (int i = 0, j = 0; s[j]; j++) {
259259
if (s[i] != s[j]) {
260260
i = j;
261-
}
261+
}
262262
ans = (ans + j - i + 1) % MOD;
263263
}
264264
return ans;

solution/2000-2099/2027.Minimum Moves to Convert String/README.md

+3-4
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555

5656
**方法一:贪心**
5757

58-
遍历字符串 $s$,只要遇到 `X`,指针就直接往后移动三格,并且答案加 $1$;否则指针往后移动一格
58+
遍历字符串 $s$,只要遇到 `'X'`,指针 $i$ 就直接往后移动三格,并且答案加 $1$;否则指针 $i$ 往后移动一格
5959

6060
时间复杂度 $O(n)$。其中 $n$ 表示字符串 $s$ 的长度。
6161

@@ -118,15 +118,14 @@ public:
118118
### **Go**
119119
120120
```go
121-
func minimumMoves(s string) int {
122-
ans := 0
121+
func minimumMoves(s string) (ans int) {
123122
for i := 0; i < len(s); i++ {
124123
if s[i] == 'X' {
125124
ans++
126125
i += 2
127126
}
128127
}
129-
return ans
128+
return
130129
}
131130
```
132131

solution/2000-2099/2027.Minimum Moves to Convert String/README_EN.md

+2-3
Original file line numberDiff line numberDiff line change
@@ -102,15 +102,14 @@ public:
102102
### **Go**
103103
104104
```go
105-
func minimumMoves(s string) int {
106-
ans := 0
105+
func minimumMoves(s string) (ans int) {
107106
for i := 0; i < len(s); i++ {
108107
if s[i] == 'X' {
109108
ans++
110109
i += 2
111110
}
112111
}
113-
return ans
112+
return
114113
}
115114
```
116115

Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1-
func minimumMoves(s string) int {
2-
ans := 0
1+
func minimumMoves(s string) (ans int) {
32
for i := 0; i < len(s); i++ {
43
if s[i] == 'X' {
54
ans++
65
i += 2
76
}
87
}
9-
return ans
8+
return
109
}

solution/2000-2099/2028.Find Missing Observations/README.md

+10
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,16 @@
6464

6565
<!-- 这里可写通用的实现逻辑 -->
6666

67+
**方法一:构造**
68+
69+
根据题目描述,所有数字之和为 $(n + m) \times mean$,已知的数字之和为 `sum(rolls)`,那么缺失的数字之和为 $s = (n + m) \times mean - sum(rolls)$。
70+
71+
如果 $s \gt n \times 6$ 或者 $s \lt n$,说明不存在满足条件的答案,返回空数组。
72+
73+
否则,我们可以将 $s$ 平均分配到 $n$ 个数字上,即每个数字的值为 $s / n$,其中 $s \bmod n$ 个数字的值再加上 $1$。
74+
75+
时间复杂度 $O(n + m)$,空间复杂度 $O(1)$。其中 $n$ 和 $m$ 分别为缺失的数字个数和已知的数字个数。
76+
6777
<!-- tabs:start -->
6878

6979
### **Python3**

solution/2500-2599/2518.Number of Great Partitions/README.md

+21
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,27 @@
5454

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

57+
**方法一:逆向思维 + 动态规划**
58+
59+
对于一个长度为 $n$ 的数组 `nums`,每个元素都可以选择放入第一个分区或第二个分区,因此一共有 $2^n$ 种分区方式。每一种分区方式,得到的结果可以是“好分区”或者“坏分区”,题目要我们求“好分区”的个数,我们可以转换为求“坏分区”的个数。那么“好分区”的个数就是 $2^n$ 减去“坏分区”的个数。
60+
61+
“坏分区”实际上就是从数组 `nums` 中选出若干个元素,使得这若干个元素之和不超过 $k$。这可以通过动态规划(0-1 背包问题)来求解。
62+
63+
我们用 $f[i][j]$ 表示从数组 `nums` 的前 $i$ 个元素中选出若干个元素,使得这若干个元素之和为 $j$ 的方案数。那么 $f[i][j]$ 的状态转移方程为:
64+
65+
$$
66+
f[i][j] = \left\{
67+
\begin{aligned}
68+
&f[i - 1][j] & \text{如果不选第 } i \text{ 个元素} \\
69+
&f[i - 1][j - nums[i - 1]] & \text{如果选第 } i \text{ 个元素}
70+
\end{aligned}
71+
\right.
72+
$$
73+
74+
那么“坏分区”的个数就是 $\sum_{j=0}^{k-1} f[n][j] \times 2$,其中 $n$ 为数组 `nums` 的长度。最后,我们用 $2^n$ 减去“坏分区”的个数,即可得到“好分区”的个数。
75+
76+
时间复杂度 $O(n \times k)$,空间复杂度 $O(n \times k)$。其中 $n$ 为数组 `nums` 的长度,而 $k$ 为整数 $k$。
77+
5778
<!-- tabs:start -->
5879

5980
### **Python3**

0 commit comments

Comments
 (0)