Skip to content

Commit ceb1a3d

Browse files
committed
3471
1 parent c155a28 commit ceb1a3d

1 file changed

Lines changed: 28 additions & 0 deletions

File tree

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
'''
2+
1. 아이디어 :
3+
k만큼의 부분배열을 만들고, 부분배열에 포함되는 갯수 센다.
4+
5+
2. 시간복잡도 :
6+
O(n*k)
7+
8+
3. 자료구조/알고리즘 :
9+
'''
10+
from collections import defaultdict
11+
class Solution:
12+
def largestInteger(self, nums: List[int], k: int) -> int:
13+
n = len(nums)
14+
dic = defaultdict(int)
15+
for i in range(n-k+1):
16+
sub = nums[i:i+k]
17+
st = set()
18+
for j in sub:
19+
st.add(j)
20+
for j in st:
21+
dic[j] += 1
22+
23+
print(dic)
24+
25+
try:
26+
return max([key for key,value in dic.items() if value == 1])
27+
except:
28+
return -1

0 commit comments

Comments
 (0)