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.
2 parents 9b7b419 + 7c372f4 commit 56231b8Copy full SHA for 56231b8
contains-duplicate/sonjh1217.swift
@@ -0,0 +1,14 @@
1
+class Solution {
2
+ // time O(n) / space O(n)
3
+ func containsDuplicate(_ nums: [Int]) -> Bool {
4
+ var numSet = Set<Int>()
5
+ for num in nums {
6
+ if numSet.contains(num) {
7
+ return true
8
+ }
9
+ numSet.insert(num)
10
11
+
12
+ return false
13
14
+}
two-sum/sonjh1217.swift
@@ -0,0 +1,15 @@
+ func twoSum(_ nums: [Int], _ target: Int) -> [Int] {
+ var indicesByCounters = [Int: Int]()
+ for (i, num) in nums.enumerated() {
+ if let index = indicesByCounters[num] {
+ return [index, i]
+ indicesByCounters[target - num] = i
+ return []
15
0 commit comments