Algorithm(218)
-
[Leetcode]1493. Longest Subarray of 1's After Deleting One Element
1. problem :https://leetcode.com/problems/longest-subarray-of-1s-after-deleting-one-element/?envType=study-plan-v2&envId=leetcode-75 2. solution 1 :from typing import Listclass Solution: def longestSubarray(self, nums: List[int]) -> int: left = 0 zero_count = 0 max_length = 0 for right in range(len(nums)): if nums[right] == 0: zero..
2024.08.03 -
[Leetcode] 875. Koko Eating Bananas(x)
1. problem : https://leetcode.com/problems/koko-eating-bananas/ 2. solution 1 :class Solution: def minEatingSpeed(self, piles: List[int], h: int) -> int: def canFinish(piles,speed,h): time = 0 for pile in piles: time += (pile - 1) // speed + 1 return time koko가 바나나를 먹을 수 있는 최대의 개수는 1개에서 max(piles) 개다. 나는 여기서 탐색할 거 빠르게 하면 좋다는 생각에 도달을 못했다..
2024.08.03 -
[Leetcode]704. Binary Search
1. problem : https://leetcode.com/problems/binary-search/ 2. solution 1 :class Solution: def search(self, nums: List[int], target: int) -> int: left,right = 0 , len(nums) -1 while left target: right = mid - 1 else: return mid return -1
2024.08.02 -
[Leetcode]84. Largest Rectangle in Histogram(x)
1. problem : https://leetcode.com/problems/largest-rectangle-in-histogram/description/ 2. solution 1 :class Solution: def largestRectangleArea(self,heights : List[int]) -> int: stack = [] index = 0 max_area = 0 while index 상당히 어렵다. stack을 쓰는 문제.. 외우자.
2024.08.02 -
[Leetcode]853. Car Fleet(x)
1. problem : https://leetcode.com/problems/car-fleet/ 2. solution 1 :class Solution: def carFleet(self, target: int, position: List[int], speed: List[int]) -> int: cars = sorted(zip(position,speed),reverse=True) times = [(target - p)/s for p,s in cars] current_time = 0 fleet = 0 for time in times: if time > current_time: fleet +=1 ..
2024.08.02 -
[Leetcode]739. Daily Temperatures(x)
1. problem : https://leetcode.com/problems/daily-temperatures/ 2. solution 1 :class Solution: def dailyTemperatures(self, temperatures: List[int]) -> List[int]: ans = [0] * len(temperatures) stack = [] for i,temp in enumerate(temperatures): while stack and temperatures[stack[-1]]
2024.08.02