Skip to content

feat: update lc problems #3488

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
Sep 4, 2024
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
6 changes: 3 additions & 3 deletions lcof2/剑指 Offer II 086. 分割回文子字符串/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -299,15 +299,15 @@ class Solution {
n = s.count
self.s = s
f = Array(repeating: Array(repeating: true, count: n), count: n)

let chars = Array(s)

for i in stride(from: n - 1, through: 0, by: -1) {
for j in i + 1 ..< n {
f[i][j] = chars[i] == chars[j] && f[i + 1][j - 1]
}
}

dfs(0)
return ans
}
Expand Down
8 changes: 4 additions & 4 deletions lcof2/剑指 Offer II 092. 翻转字符/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -188,22 +188,22 @@ class Solution {
let n = s.count
var left0 = 0, right0 = 0
let chars = Array(s)

for char in chars {
if char == "0" {
right0 += 1
}
}

var ans = min(right0, n - right0)

for i in 1...n {
let x = chars[i - 1] == "0" ? 0 : 1
right0 -= x ^ 1
left0 += x ^ 1
ans = min(ans, i - left0 + right0)
}

return ans
}
}
Expand Down
6 changes: 3 additions & 3 deletions lcof2/剑指 Offer II 093. 最长斐波那契数列/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -198,10 +198,10 @@ class Solution {
for i in 0..<n {
mp[arr[i]] = i
}

var dp = Array(repeating: Array(repeating: 2, count: n), count: n)
var ans = 0

for i in 0..<n {
for j in 0..<i {
let delta = arr[i] - arr[j]
Expand All @@ -211,7 +211,7 @@ class Solution {
}
}
}

return ans > 2 ? ans : 0
}
}
Expand Down
10 changes: 5 additions & 5 deletions lcof2/剑指 Offer II 094. 最少回文分割/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -256,28 +256,28 @@ class Solution {
func minCut(_ s: String) -> Int {
let n = s.count
let sArray = Array(s)

var g = Array(repeating: Array(repeating: true, count: n), count: n)

for i in stride(from: n - 1, through: 0, by: -1) {
for j in i + 1..<n {
g[i][j] = sArray[i] == sArray[j] && g[i + 1][j - 1]
}
}

var f = Array(repeating: 0, count: n)
for i in 0..<n {
f[i] = i
}

for i in 1..<n {
for j in 0...i {
if g[j][i] {
f[i] = min(f[i], j > 0 ? 1 + f[j - 1] : 0)
}
}
}

return f[n - 1]
}
}
Expand Down
6 changes: 3 additions & 3 deletions lcof2/剑指 Offer II 096. 字符串交织/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -694,11 +694,11 @@ class Solution {
if m + n != s3.count {
return false
}

let s1 = Array(s1), s2 = Array(s2), s3 = Array(s3)
var dp = Array(repeating: Array(repeating: false, count: n + 1), count: m + 1)
dp[0][0] = true

for i in 0...m {
for j in 0...n {
let k = i + j - 1
Expand All @@ -710,7 +710,7 @@ class Solution {
}
}
}

return dp[m][n]
}
}
Expand Down
1 change: 1 addition & 0 deletions solution/2800-2899/2860.Happy Students/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ class Solution:
continue
if i < n and nums[i] <= i:
continue
ans += 1
return ans
```

Expand Down
1 change: 1 addition & 0 deletions solution/2800-2899/2860.Happy Students/README_EN.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ class Solution:
continue
if i < n and nums[i] <= i:
continue
ans += 1
return ans
```

Expand Down
1 change: 1 addition & 0 deletions solution/2800-2899/2860.Happy Students/Solution.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ def countWays(self, nums: List[int]) -> int:
continue
if i < n and nums[i] <= i:
continue
ans += 1
return ans
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ tags:
<strong>输入:</strong>source = "aaaa", target = "bbbb", original = ["a","c"], changed = ["c","b"], cost = [1,2]
<strong>输出:</strong>12
<strong>解释:</strong>要将字符 'a' 更改为 'b':
- 将字符 'a' 更改为 'c',成本为 1
- 将字符 'c' 更改为 'b',成本为 2
- 将字符 'a' 更改为 'c',成本为 1
- 将字符 'c' 更改为 'b',成本为 2
产生的总成本是 1 + 2 = 3。
将所有 'a' 更改为 'b',产生的总成本是 3 * 4 = 12 。
</pre>
Expand Down
4 changes: 2 additions & 2 deletions solution/3200-3299/3268.Find Overlapping Shifts II/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@ tags:
这张表包含员工的排班工作,包括特定日期的开始和结束时间。
</pre>

<p>编写一个解决方案来为每个员工分析重叠排班。如果一个排班的&nbsp;<code>end_time</code>&nbsp;比另一个排班的&nbsp;<code>start_time</code>&nbsp;<strong>更晚&nbsp;</strong>则认为两个排班重叠。</p>
<p>编写一个解决方案来为每个员工分析重叠排班。如果两个排班在&nbsp;<strong>同一天</strong>&nbsp;且一个排班的&nbsp;<code>end_time</code>&nbsp;比另一个排班的&nbsp;<code>start_time</code>&nbsp;<strong>更晚&nbsp;</strong>则认为两个排班重叠。</p>

<p>对于&nbsp;<strong>每个员工</strong>,计算如下内容:</p>

<ol>
<li>任何 <strong>给定时间</strong><strong>重叠&nbsp;</strong>的 <strong>最大</strong> 班次数。</li>
<li>任何 <strong>给定时间</strong> 的 <strong>最多重叠</strong> 班次数。</li>
<li>所有重叠班次的 <strong>总持续时间</strong>,以分钟为单位。</li>
</ol>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
comments: true
difficulty: 困难
edit_url: https://github.com/doocs/leetcode/edit/main/solution/3200-3299/3269.Constructing%20Two%20Increasing%20Arrays/README.md
tags:
- 数组
- 动态规划
---

<!-- problem:start -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
comments: true
difficulty: Hard
edit_url: https://github.com/doocs/leetcode/edit/main/solution/3200-3299/3269.Constructing%20Two%20Increasing%20Arrays/README_EN.md
tags:
- Array
- Dynamic Programming
---

<!-- problem:start -->
Expand Down
2 changes: 2 additions & 0 deletions solution/3200-3299/3270.Find the Key of the Numbers/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
comments: true
difficulty: 简单
edit_url: https://github.com/doocs/leetcode/edit/main/solution/3200-3299/3270.Find%20the%20Key%20of%20the%20Numbers/README.md
tags:
- 数学
---

<!-- problem:start -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
comments: true
difficulty: Easy
edit_url: https://github.com/doocs/leetcode/edit/main/solution/3200-3299/3270.Find%20the%20Key%20of%20the%20Numbers/README_EN.md
tags:
- Math
---

<!-- problem:start -->
Expand Down
3 changes: 3 additions & 0 deletions solution/3200-3299/3271.Hash Divided String/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
comments: true
difficulty: 中等
edit_url: https://github.com/doocs/leetcode/edit/main/solution/3200-3299/3271.Hash%20Divided%20String/README.md
tags:
- 字符串
- 模拟
---

<!-- problem:start -->
Expand Down
3 changes: 3 additions & 0 deletions solution/3200-3299/3271.Hash Divided String/README_EN.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
comments: true
difficulty: Medium
edit_url: https://github.com/doocs/leetcode/edit/main/solution/3200-3299/3271.Hash%20Divided%20String/README_EN.md
tags:
- String
- Simulation
---

<!-- problem:start -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
comments: true
difficulty: 困难
edit_url: https://github.com/doocs/leetcode/edit/main/solution/3200-3299/3272.Find%20the%20Count%20of%20Good%20Integers/README.md
tags:
- 哈希表
- 数学
- 组合数学
- 枚举
---

<!-- problem:start -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
comments: true
difficulty: Hard
edit_url: https://github.com/doocs/leetcode/edit/main/solution/3200-3299/3272.Find%20the%20Count%20of%20Good%20Integers/README_EN.md
tags:
- Hash Table
- Math
- Combinatorics
- Enumeration
---

<!-- problem:start -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
comments: true
difficulty: 困难
edit_url: https://github.com/doocs/leetcode/edit/main/solution/3200-3299/3273.Minimum%20Amount%20of%20Damage%20Dealt%20to%20Bob/README.md
tags:
- 贪心
- 数组
- 排序
---

<!-- problem:start -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
comments: true
difficulty: Hard
edit_url: https://github.com/doocs/leetcode/edit/main/solution/3200-3299/3273.Minimum%20Amount%20of%20Damage%20Dealt%20to%20Bob/README_EN.md
tags:
- Greedy
- Array
- Sorting
---

<!-- problem:start -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
comments: true
difficulty: 简单
edit_url: https://github.com/doocs/leetcode/edit/main/solution/3200-3299/3274.Check%20if%20Two%20Chessboard%20Squares%20Have%20the%20Same%20Color/README.md
tags:
- 数学
- 字符串
---

<!-- problem:start -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
comments: true
difficulty: Easy
edit_url: https://github.com/doocs/leetcode/edit/main/solution/3200-3299/3274.Check%20if%20Two%20Chessboard%20Squares%20Have%20the%20Same%20Color/README_EN.md
tags:
- Math
- String
---

<!-- problem:start -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
comments: true
difficulty: 中等
edit_url: https://github.com/doocs/leetcode/edit/main/solution/3200-3299/3275.K-th%20Nearest%20Obstacle%20Queries/README.md
tags:
- 数组
- 堆(优先队列)
---

<!-- problem:start -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
comments: true
difficulty: Medium
edit_url: https://github.com/doocs/leetcode/edit/main/solution/3200-3299/3275.K-th%20Nearest%20Obstacle%20Queries/README_EN.md
tags:
- Array
- Heap (Priority Queue)
---

<!-- problem:start -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@
comments: true
difficulty: 困难
edit_url: https://github.com/doocs/leetcode/edit/main/solution/3200-3299/3276.Select%20Cells%20in%20Grid%20With%20Maximum%20Score/README.md
tags:
- 位运算
- 数组
- 动态规划
- 状态压缩
- 矩阵
---

<!-- problem:start -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@
comments: true
difficulty: Hard
edit_url: https://github.com/doocs/leetcode/edit/main/solution/3200-3299/3276.Select%20Cells%20in%20Grid%20With%20Maximum%20Score/README_EN.md
tags:
- Bit Manipulation
- Array
- Dynamic Programming
- Bitmask
- Matrix
---

<!-- problem:start -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
comments: true
difficulty: 困难
edit_url: https://github.com/doocs/leetcode/edit/main/solution/3200-3299/3277.Maximum%20XOR%20Score%20Subarray%20Queries/README.md
tags:
- 数组
- 动态规划
---

<!-- problem:start -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
comments: true
difficulty: Hard
edit_url: https://github.com/doocs/leetcode/edit/main/solution/3200-3299/3277.Maximum%20XOR%20Score%20Subarray%20Queries/README_EN.md
tags:
- Array
- Dynamic Programming
---

<!-- problem:start -->
Expand Down
Loading
Loading