Skip to content

Commit 4b72ba0

Browse files
authored
feat: update lc problems (#2988)
1 parent 92c9e06 commit 4b72ba0

File tree

12 files changed

+26
-26
lines changed
  • lcof2
    • 剑指 Offer II 005. 单词长度的最大乘积
    • 剑指 Offer II 008. 和大于等于 target 的最短子数组
    • 剑指 Offer II 009. 乘积小于 K 的子数组
    • 剑指 Offer II 010. 和为 k 的子数组
    • 剑指 Offer II 011. 0 和 1 个数相同的子数组
    • 剑指 Offer II 012. 左右两边子数组的和相等
    • 剑指 Offer II 013. 二维子矩阵的和
    • 剑指 Offer II 014. 字符串中的变位词
  • solution

12 files changed

+26
-26
lines changed

lcof2/剑指 Offer II 005. 单词长度的最大乘积/README.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -188,13 +188,13 @@ class Solution {
188188
func maxProduct(_ words: [String]) -> Int {
189189
let n = words.count
190190
var masks = [Int](repeating: 0, count: n)
191-
191+
192192
for i in 0..<n {
193193
for c in words[i] {
194194
masks[i] |= 1 << (c.asciiValue! - Character("a").asciiValue!)
195195
}
196196
}
197-
197+
198198
var maxProduct = 0
199199
for i in 0..<n {
200200
for j in i+1..<n {
@@ -203,7 +203,7 @@ class Solution {
203203
}
204204
}
205205
}
206-
206+
207207
return maxProduct
208208
}
209209
}

lcof2/剑指 Offer II 008. 和大于等于 target 的最短子数组/README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ class Solution {
185185
var ans = inf
186186
var sum = 0
187187
var i = 0
188-
188+
189189
for j in 0..<nums.count {
190190
sum += nums[j]
191191
while sum >= target {
@@ -194,7 +194,7 @@ class Solution {
194194
i += 1
195195
}
196196
}
197-
197+
198198
return ans == inf ? 0 : ans
199199
}
200200
}

lcof2/剑指 Offer II 009. 乘积小于 K 的子数组/README.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -155,11 +155,11 @@ function numSubarrayProductLessThanK(nums: number[], k: number): number {
155155
class Solution {
156156
func numSubarrayProductLessThanK(_ nums: [Int], _ k: Int) -> Int {
157157
if k <= 1 { return 0 }
158-
158+
159159
var product: Int = 1
160160
var ans: Int = 0
161161
var left: Int = 0
162-
162+
163163
for right in 0..<nums.count {
164164
product *= nums[right]
165165
while product >= k {
@@ -168,7 +168,7 @@ class Solution {
168168
}
169169
ans += right - left + 1
170170
}
171-
171+
172172
return ans
173173
}
174174
}

lcof2/剑指 Offer II 010. 和为 k 的子数组/README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -151,13 +151,13 @@ class Solution {
151151
var cnt: [Int: Int] = [0: 1]
152152
var ans = 0
153153
var s = 0
154-
154+
155155
for x in nums {
156156
s += x
157157
ans += cnt[s - k, default: 0]
158158
cnt[s, default: 0] += 1
159159
}
160-
160+
161161
return ans
162162
}
163163
}

lcof2/剑指 Offer II 011. 0 和 1 个数相同的子数组/README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ class Solution {
169169
var d: [Int: Int] = [0: -1]
170170
var ans = 0
171171
var s = 0
172-
172+
173173
for i in 0..<nums.count {
174174
s += nums[i] == 0 ? -1 : 1
175175
if let prevIndex = d[s] {
@@ -178,7 +178,7 @@ class Solution {
178178
d[s] = i
179179
}
180180
}
181-
181+
182182
return ans
183183
}
184184
}

lcof2/剑指 Offer II 012. 左右两边子数组的和相等/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ class Solution {
233233
func pivotIndex(_ nums: [Int]) -> Int {
234234
var leftSum = 0
235235
var rightSum = nums.reduce(0, +)
236-
236+
237237
for i in 0..<nums.count {
238238
rightSum -= nums[i]
239239
if leftSum == rightSum {

lcof2/剑指 Offer II 013. 二维子矩阵的和/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ class NumMatrix {
264264
let m = matrix.count
265265
let n = matrix[0].count
266266
prefixSum = Array(repeating: Array(repeating: 0, count: n + 1), count: m + 1)
267-
267+
268268
for i in 1...m {
269269
for j in 1...n {
270270
prefixSum[i][j] = prefixSum[i - 1][j] + prefixSum[i][j - 1] - prefixSum[i - 1][j - 1] + matrix[i - 1][j - 1]

lcof2/剑指 Offer II 014. 字符串中的变位词/README.md

+6-6
Original file line numberDiff line numberDiff line change
@@ -450,29 +450,29 @@ class Solution {
450450
if m > n {
451451
return false
452452
}
453-
453+
454454
var cnt1 = [Int](repeating: 0, count: 26)
455455
var cnt2 = [Int](repeating: 0, count: 26)
456456
let aAscii = Character("a").asciiValue!
457-
457+
458458
for i in 0..<m {
459459
cnt1[Int(s1[s1.index(s1.startIndex, offsetBy: i)].asciiValue! - aAscii)] += 1
460460
cnt2[Int(s2[s2.index(s2.startIndex, offsetBy: i)].asciiValue! - aAscii)] += 1
461461
}
462-
462+
463463
if cnt1 == cnt2 {
464464
return true
465465
}
466-
466+
467467
for i in m..<n {
468468
cnt2[Int(s2[s2.index(s2.startIndex, offsetBy: i)].asciiValue! - aAscii)] += 1
469469
cnt2[Int(s2[s2.index(s2.startIndex, offsetBy: i - m)].asciiValue! - aAscii)] -= 1
470-
470+
471471
if cnt1 == cnt2 {
472472
return true
473473
}
474474
}
475-
475+
476476
return false
477477
}
478478
}

solution/2400-2499/2473.Minimum Cost to Buy Apples/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ tags:
2727

2828
<p>你从某个城市开始,穿越各种道路,最终从&nbsp;<strong>任何一个&nbsp;</strong>城市买&nbsp;<strong>一个&nbsp;</strong>苹果。在你买了那个苹果之后,你必须回到你&nbsp;<strong>开始的&nbsp;</strong>城市,但现在所有道路的成本将&nbsp;<strong>乘以&nbsp;</strong>一个给定的因子 <code>k</code>。</p>
2929

30-
<p>给定整数 <code>k</code>,返回<em>一个大小为 <code>n</code> 的数组 <code>answer</code>,其中 <code>answer[i]</code>&nbsp;是从城市 <code>i</code> 开始购买一个苹果的&nbsp;<strong>最小&nbsp;</strong>总成本。</em></p>
30+
<p>给定整数 <code>k</code>,返回<em>一个大小为 <code>n</code> 的从 1 开始的数组 <code>answer</code>,其中 <code>answer[i]</code>&nbsp;是从城市 <code>i</code> 开始购买一个苹果的&nbsp;<strong>最小&nbsp;</strong>总成本。</em></p>
3131

3232
<p>&nbsp;</p>
3333

solution/3100-3199/3166.Calculate Parking Fees and Duration/README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -83,13 +83,13 @@ tags:
8383
<li>从 2023-06-01 10:45:00 到 2023-06-01 12:00:00 在停车场 2:1.25 小时,费用 6.00</li>
8484
<li>从 2023-06-03 07:00:00 到 2023-06-03 09:00:00 在停车场 3:2 小时,费用 4.00</li>
8585
</ul>
86-
总共支付费用:18.00,总小时:7.5,每小时平均费用:2.40,停车场 1 总花费时间最长:2.5 小时。</li>
86+
总共支付费用:18.00,总小时:7.5,每小时平均费用:2.40,停车场 1 总花费时间最长:4.25&nbsp;小时。</li>
8787
<li>对于汽车 ID 1002:
8888
<ul>
8989
<li>从 2023-06-01 09:00:00 到 2023-06-01 11:30:00 在停车场 2:2.5 小时,费用 4.00</li>
9090
<li>从 2023-06-02 12:00:00 到 2023-06-02 14:00:00 在停车场 3:2 小时,费用 2.00</li>
9191
</ul>
92-
总共支付费用:6.00,总小时:4.5,每小时平均费用:1.33,停车场 2 总花费时间最长:4.25 小时。</li>
92+
总共支付费用:6.00,总小时:4.5,每小时平均费用:1.33,停车场 2 总花费时间最长:2.5 小时。</li>
9393
</ul>
9494

9595
<p><b>注意:</b>&nbsp;输出表以 car_id 升序排序。</p>

solution/3100-3199/3166.Calculate Parking Fees and Duration/README_EN.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ Each row of this table contains the ID of the parking lot, the ID of the car, th
8282
<li>From 2023-06-01 10:45:00 to 2023-06-01 12:00:00 in lot 2: 1.25 hours, fee 6.00</li>
8383
<li>From 2023-06-03 07:00:00 to 2023-06-03 09:00:00 in lot 3: 2 hours, fee 4.00</li>
8484
</ul>
85-
Total fee paid: 18.00, total hours: 7.5, average hourly fee: 2.40, most time spent in lot 1: 2.5 hours.</li>
85+
Total fee paid: 18.00, total hours: 7.5, average hourly fee: 2.40, most time spent in lot 1: 4.25 hours.</li>
8686
<li>For car ID 1002:
8787
<ul>
8888
<li>From 2023-06-01 09:00:00 to 2023-06-01 11:30:00 in lot 2: 2.5 hours, fee 4.00</li>

solution/3100-3199/3167.Better Compression of String/README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,9 @@ edit_url: https://github.com/doocs/leetcode/edit/main/solution/3100-3199/3167.Be
3838

3939
<p><strong>解释:</strong></p>
4040

41-
<p>字符 "a" 和 "b" 在输入中只出现了一次,但 "c" 出现了两次,第一次出现了 9 次,另一次是 1 次。</p>
41+
<p>字符 "a" 和 "b" 在输入中只出现了一次,但 "c" 出现了两次,第一次长度为 9,另一次是长度为 1。</p>
4242

43-
<p>因此,在结果字符串中,它应当出现 10。</p>
43+
<p>因此,在结果字符串中,它应当长度为 10。</p>
4444
</div>
4545

4646
<p><strong class="example">示例 2:</strong></p>

0 commit comments

Comments
 (0)