Skip to content

Commit 9219dff

Browse files
committed
1124,239
1 parent d4d3b82 commit 9219dff

2 files changed

Lines changed: 51 additions & 0 deletions

File tree

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
2+
class Solution:
3+
def run(self, hours):
4+
lst = [1 if hour > 8 else -1 for hour in hours]
5+
n = len(lst)
6+
tmp = [0] * n
7+
tmp[0] = max(lst[0],0)
8+
for i in range(1,n):
9+
tmp[i] = max(tmp[i-1]+lst[i],0)
10+
print(tmp)
11+
12+
streak = 0
13+
_max = -1
14+
for i in tmp:
15+
# print(i, streak, _max)
16+
if i != 0:
17+
streak +=1
18+
else:
19+
streak = 0
20+
21+
if streak > _max:
22+
_max = streak
23+
24+
return _max
25+
26+
def longestWPI(self, hours: list[int]) -> int:
27+
return max(self.run(hours), self.run(hours[::-1]))
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
'''
2+
1. 아이디어 :
3+
절대값 작은거 찾고, 해당 num을 기록해둠.
4+
그리고 같은 절대값이 나오면 num끼리 비교해서 더 큰거 선택
5+
6+
2. 시간복잡도 :
7+
o(n)
8+
9+
3. 자료구조/알고리즘 :
10+
'''
11+
class Solution:
12+
def findClosestNumber(self, nums: list[int]) -> int:
13+
_min, value = 9999999, 9999999
14+
15+
for num in nums:
16+
print(num, _min,value)
17+
if abs(num) < _min:
18+
_min,value = abs(num), num
19+
elif abs(num) == _min:
20+
if num > value:
21+
value = num
22+
23+
return value
24+

0 commit comments

Comments
 (0)