diff --git "a/leetcode3/\354\206\241\354\243\274\355\230\234/1503. Last Moment Before All Ants Fall Out of a Plank" "b/leetcode3/\354\206\241\354\243\274\355\230\234/1503. Last Moment Before All Ants Fall Out of a Plank" new file mode 100644 index 00000000..f5491aef --- /dev/null +++ "b/leetcode3/\354\206\241\354\243\274\355\230\234/1503. Last Moment Before All Ants Fall Out of a Plank" @@ -0,0 +1,16 @@ +class Solution: + def getLastMoment(self, n: int, left: list[int], right: list[int]) -> int: + ants = [[i, -1] for i in left] + [[i, 1] for i in right] # 왼쪽은 -1, 오른쪽은 1 + time = 0 + live = [] + + for i in ants: + x, y = i[0], i[1] + + if x == 0 and y == -1: # 0에서 왼쪽 방향이면 떨어짐 + continue + if x == n and y == 1: + continue + live.append(i) + ants = live + diff --git "a/leetcode3/\354\206\241\354\243\274\355\230\234/1695. Maximum Erasure Value" "b/leetcode3/\354\206\241\354\243\274\355\230\234/1695. Maximum Erasure Value" new file mode 100644 index 00000000..93540f72 --- /dev/null +++ "b/leetcode3/\354\206\241\354\243\274\355\230\234/1695. Maximum Erasure Value" @@ -0,0 +1,20 @@ +class Solution: + def maximumUniqueSubarray(self, nums: list[int]) -> int: + numbers = set() + total = 0 + answer = 0 + rm = 0 + + for i in range(len(nums)): + + while nums[i] in numbers: + numbers.remove(nums[rm]) + total -= nums[rm] + rm += 1 + + # numbers에 없으면 추가 + numbers.add(nums[i]) + total += nums[i] + answer = max(answer, total) + + return answer