Skip to content

Commit d56d75d

Browse files
committed
To fix the sorted{ xxx } to sorted() & Add soapyigu flat-reduce solution
Signed-off-by: Desgard_Duan <gua@desgard.com>
1 parent 4da412c commit d56d75d

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

README.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
* [Microsoft](#microsoft)
2828

2929
## Progress
30-
[Problem Status](#problem-status) shows the latest progress to all 500+ questions. Currently we have 219 completed solutions. Note: questions with &hearts; mark means that you have to **Subscript to premium membership** of LeetCode to unlock them. Thank you for great contributions from [CharleneJiang](https://github.com/CharleneJiang), [ReadmeCritic](https://github.com/ReadmeCritic), [demonkoo](https://github.com/demonkoo), [DaiYue](https://github.com/DaiYue), [Quaggie](https://github.com/Quaggie) and [jindulys](https://github.com/jindulys).
30+
[Problem Status](#problem-status) shows the latest progress to all 500+ questions. Currently we have 221 completed solutions. Note: questions with &hearts; mark means that you have to **Subscript to premium membership** of LeetCode to unlock them. Thank you for great contributions from [CharleneJiang](https://github.com/CharleneJiang), [ReadmeCritic](https://github.com/ReadmeCritic), [demonkoo](https://github.com/demonkoo), [DaiYue](https://github.com/DaiYue), [Quaggie](https://github.com/Quaggie) and [jindulys](https://github.com/jindulys).
3131

3232

3333
## Array
@@ -189,7 +189,6 @@
189189
[Burst Ballons](https://leetcode.com/problems/burst-balloons/)| [Swift](./DP/BurstBalloons.swift)| Hard| O(n^3)| O(n)|
190190
[Frog Jump](https://leetcode.com/problems/frog-jump/)| [Swift](./DP/FrogJump.swift)| Hard| O(n^2)| O(n)|
191191

192-
193192
## Depth-first search
194193
| Title | Solution | Difficulty | Time | Space |
195194
| ----- | -------- | ---------- | ---- | ----- |
@@ -771,4 +770,3 @@
771770
| [Swift](./Math/AddTwoNumbers.swift) | 2 | [Add Two Numbers](https://leetcode.com/problems/add-two-numbers/) | Medium |
772771
| [Swift](./Array/TwoSum.swift) | 1 | [Two Sum](https://leetcode.com/problems/two-sum/) | Easy |
773772

774-

Sort/ArrayPartitionI.swift

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
class ArrayPartitionI {
22
func arrayPairSum(_ nums: [Int]) -> Int {
33
var arr = nums
4-
arr = arr.sorted { $0 < $1 }
4+
arr = arr.sorted()
55
var res = 0
66
for i in 0 ..< arr.count {
77
if i & 1 != 0 {
@@ -11,3 +11,11 @@ class ArrayPartitionI {
1111
return res
1212
}
1313
}
14+
15+
class ArrayPartitionI_2 {
16+
func arrayPairSum(_ nums: [Int]) -> Int {
17+
return nums.sorted(by: <).enumerated()
18+
.flatMap { $0 % 2 == 0 ? $1 : nil }
19+
.reduce(0) { $0 + $1 }
20+
}
21+
}

0 commit comments

Comments
 (0)