Skip to content

Commit 45660e3

Browse files
committed
🎉 feat: initial commit for leetcode 169 using Swift
1 parent 5813b95 commit 45660e3

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

Swift/169. Majority Element.swift

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// 169. Majority Element
2+
// 60 ms
3+
var v = 0, res = 0
4+
var dict = [Int: Int]()
5+
nums.forEach {
6+
var t = 1
7+
if let n = dict[$0] {
8+
t = n + 1
9+
}
10+
11+
if t > v {
12+
res = $0
13+
v = t
14+
}
15+
dict[$0] = t
16+
}
17+
18+
return res

0 commit comments

Comments
 (0)