Skip to content

Commit 421f406

Browse files
committed
solve problem
1 parent 12fc06f commit 421f406

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
class Solution {
2+
func lengthOfLIS(_ nums: [Int]) -> Int {
3+
var tails: [Int] = []
4+
for num in nums {
5+
if let lastValue = tails.last {
6+
if num > lastValue {
7+
tails.append(num)
8+
} else {
9+
if let index = tails.firstIndex(where: { $0 >= num }) {
10+
tails[index] = num
11+
}
12+
}
13+
} else {
14+
tails.append(num)
15+
}
16+
}
17+
18+
return tails.count
19+
}
20+
}
21+

0 commit comments

Comments
 (0)