Skip to content

Commit 12a67d0

Browse files
committed
Add 1641 & 1679
1 parent 8724ecb commit 12a67d0

File tree

3 files changed

+41
-0
lines changed

3 files changed

+41
-0
lines changed

Array/MaxNumberOfK-SumPairs.swift

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
class Solution {
2+
func maxOperations(_ nums: [Int], _ k: Int) -> Int {
3+
var rest = [Int: Int]()
4+
var result = 0
5+
for num in nums {
6+
if let count = rest[k-num], count > 0 {
7+
rest[k-num] = count-1
8+
result += 1
9+
} else {
10+
rest[num, default: 0] += 1
11+
}
12+
}
13+
14+
return result
15+
}
16+
}

DP/CountSortedVowelStrings.swift

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
class Solution {
2+
func countVowelStrings(_ n: Int) -> Int {
3+
var curr = [0, 0, 0, 0, 1]
4+
5+
for _ in 1..<n {
6+
var next = [Int]()
7+
var sum = 0
8+
for x in (0..<curr.count).reversed() {
9+
sum += curr[x]
10+
next.insert(sum, at:0)
11+
}
12+
curr = next
13+
}
14+
15+
var result = 0
16+
for x in 0..<curr.count {
17+
result += curr[x] * (x+1)
18+
}
19+
return result
20+
}
21+
}

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
## Array
4343
| Title | Solution | Difficulty | Time | Space |
4444
| ----- | -------- | ---------- | ---- | ----- |
45+
[Max Number of K-Sum Pairs](https://leetcode.com/problems/max-number-of-k-sum-pairs/)|[Swift](./Array/MaxNumberOfK-SumPairs.swift)| Medium| O(n)| O(n)|
4546
[Check Array Formation Through Concatenation](https://leetcode.com/problems/check-array-formation-through-concatenation/)|[Swift](./Array/CheckArrayFormationThroughConcatenation.swift)| Easy| O(nlogn)| O(n)|
4647
[Verify an Alien Dictionary](https://leetcode.com/problems/verifying-an-alien-dictionary/)|[Swift](Array/VerifyingAlienDictionary.swift)| Easy| O(n)| O(n)|
4748
[Sort Array By Parity](https://leetcode.com/problems/sort-array-by-parity/)|[Swift](./Array/SortArrayByParity.swift)| Easy| O(n)| O(n)|
@@ -225,6 +226,7 @@
225226
## Dynamic programming
226227
| Title | Solution | Difficulty | Time | Space |
227228
| ----- | -------- | ---------- | ---- | ----- |
229+
[Count Sorted Vowel Strings](https://leetcode.com/problems/count-sorted-vowel-strings/) | [Swift](./DP/CountSortedVowelStrings.swift) | Medium| O(n)| O(n)|
228230
[Minimum Operations to Reduce X to Zero](https://leetcode.com/problems/minimum-operations-to-reduce-x-to-zero/) | [Swift](./DP/MinimumOperationsToReduceXToZero.swift) | Medium| O(n)| O(n)|
229231
[Boats to Save People](https://leetcode.com/problems/boats-to-save-people/) | [Swift](./DP/BoatsToSavePeople.swift) | Medium| O(nlogn)| O(n)|
230232
[Nested List Weight Sum](https://leetcode.com/problems/nested-list-weight-sum/)| [Swift](./DP/NestedListWeightSum.swift)| Easy| O(n)| O(1)|
@@ -548,7 +550,9 @@
548550
## Problem Status
549551
| Solution | Number | Title | Difficulty |
550552
| -------- | ------ | ----- | ---------- |
553+
| [Swift](./Array/MaxNumberOfK-SumPairs.swift) | 1679 | [Max Number of K-Sum Pairs](https://leetcode.com/problems/max-number-of-k-sum-pairs/) | Medium |
551554
| [Swift](./DP/MinimumOperationsToReduceXToZero.swift) | 1658 | [Minimum Operations to Reduce X to Zero](https://leetcode.com/problems/minimum-operations-to-reduce-x-to-zero/) | Medium |
555+
| [Swift](./DP/CountSortedVowelStrings.swift) | 1641 | [Count Sorted Vowel Strings](https://leetcode.com/problems/count-sorted-vowel-strings/) | Medium |
552556
| [Swift](./Array/CheckArrayFormationThroughConcatenation.swift) | 1640 | [Check Array Formation Through Concatenation](https://leetcode.com/problems/check-array-formation-through-concatenation/) | Easy |
553557
| [Swift](./LinkedList/PseudoPalindromicPathsInABinaryTree.swift) | 1457 | [Pseudo-Palindromic Paths in a Binary Tree](https://leetcode.com/problems/pseudo-palindromic-paths-in-a-binary-tree/) | Medium |
554558
| [Swift](./BFS/JumpGameIV.swift) | 1345 | [Jump Game IV](https://leetcode.com/problems/jump-game-iv/) | Hard |

0 commit comments

Comments
 (0)