Skip to content

Commit eb65747

Browse files
authored
오우
1 parent b883529 commit eb65747

1 file changed

Lines changed: 33 additions & 0 deletions

File tree

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
let nk = readLine()!.split(separator: " ").compactMap { Int($0) }
2+
let n = nk[0]
3+
let k = nk[1]
4+
let nums = readLine()!.split(separator: " ").compactMap { Int($0) }
5+
6+
var count: [Int: Int] = [:]
7+
var left = 0
8+
var right = 0
9+
var result = 0
10+
11+
while right < n {
12+
let num = nums[right]
13+
count[num, default: 0] += 1
14+
15+
// 1차 생각: 실패
16+
// if count[num]! > k {
17+
// count[nums[left]]! -= 1
18+
// left += 1
19+
// } else {
20+
// result = max(result, right - left + 1)
21+
// right += 1
22+
// }
23+
24+
while count[num]! > k {
25+
count[nums[left]]! -= 1
26+
left += 1
27+
}
28+
29+
result = max(result, right - left + 1)
30+
right += 1
31+
}
32+
33+
print(result)

0 commit comments

Comments
 (0)