We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent b8af01d commit e6a08cfCopy full SHA for e6a08cf
3sum/delight010.swift
@@ -0,0 +1,25 @@
1
+class Solution {
2
+ func threeSum(_ nums: [Int]) -> [[Int]] {
3
+ let nums = nums.sorted()
4
+ var answer: Set<[Int]> = []
5
+ for (index, num) in nums.enumerated() {
6
+ var leftIndex = index + 1
7
+ var rightIndex = nums.endIndex - 1
8
+ while leftIndex < rightIndex {
9
+ let sum = num + nums[leftIndex] + nums[rightIndex]
10
+ if sum == 0 {
11
+ answer.insert([num, nums[leftIndex], nums[rightIndex]])
12
+ leftIndex += 1
13
+ rightIndex -= 1
14
+ } else if sum < 0 {
15
16
+ } else if sum > 0 {
17
18
+ }
19
20
21
+
22
+ return Array(answer)
23
24
+}
25
0 commit comments