Skip to content

Commit

Permalink
To fix the sorted{ xxx } to sorted() & Add soapyigu flat-reduce solution
Browse files Browse the repository at this point in the history
Signed-off-by: Desgard_Duan <[email protected]>
  • Loading branch information
Desgard committed Aug 11, 2017
1 parent 4da412c commit d56d75d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
4 changes: 1 addition & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
* [Microsoft](#microsoft)

## Progress
[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).
[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).


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


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


10 changes: 9 additions & 1 deletion Sort/ArrayPartitionI.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
class ArrayPartitionI {
func arrayPairSum(_ nums: [Int]) -> Int {
var arr = nums
arr = arr.sorted { $0 < $1 }
arr = arr.sorted()
var res = 0
for i in 0 ..< arr.count {
if i & 1 != 0 {
Expand All @@ -11,3 +11,11 @@ class ArrayPartitionI {
return res
}
}

class ArrayPartitionI_2 {
func arrayPairSum(_ nums: [Int]) -> Int {
return nums.sorted(by: <).enumerated()
.flatMap { $0 % 2 == 0 ? $1 : nil }
.reduce(0) { $0 + $1 }
}
}

0 comments on commit d56d75d

Please sign in to comment.