diff --git "a/leetcode3/\354\230\244\354\235\200\355\230\201/1348. Tweet Counts Per Frequency" "b/leetcode3/\354\230\244\354\235\200\355\230\201/1348. Tweet Counts Per Frequency" new file mode 100644 index 00000000..e90c566e --- /dev/null +++ "b/leetcode3/\354\230\244\354\235\200\355\230\201/1348. Tweet Counts Per Frequency" @@ -0,0 +1,40 @@ +class TweetCounts: + + def __init__(self): + self.tweets={} + self.time_dict={"minute":60,"hour":3600,"day":86400} + + + def recordTweet(self, tweetName: str, time: int) -> None: + if tweetName in self.tweets: + + self.tweets[tweetName].append(time) + else: + self.tweets[tweetName]=[time] + + + def getTweetCountsPerFrequency(self, freq: str, tweetName: str, startTime: int, endTime: int) -> list[int]: + self.ans=[] + + while startTime<=endTime: + cnt=0 + for a in self.tweets[tweetName]: + if a>=startTime and a<=startTime+self.time_dict[freq]-1: + cnt+=1 + self.ans.append(cnt) + + + startTime+=self.time_dict[freq] + return self.ans + + + + + + + + +# Your TweetCounts object will be instantiated and called as such: +# obj = TweetCounts() +# obj.recordTweet(tweetName,time) +# param_2 = obj.getTweetCountsPerFrequency(freq,tweetName,startTime,endTime) diff --git "a/leetcode3/\354\230\244\354\235\200\355\230\201/1536. Minimum Swaps to Arrange a Binary Grid" "b/leetcode3/\354\230\244\354\235\200\355\230\201/1536. Minimum Swaps to Arrange a Binary Grid" new file mode 100644 index 00000000..fcf943fa --- /dev/null +++ "b/leetcode3/\354\230\244\354\235\200\355\230\201/1536. Minimum Swaps to Arrange a Binary Grid" @@ -0,0 +1,32 @@ +class Solution: + + def is_poss(self,grid,y,need): + for x in range(len(grid)-need,len(grid) ): + if grid[y][x]==1:return False + return True + def swap(self,grid,a,b): + temp=grid[a] + grid[a]=grid[b] + grid[b]=temp + + + + def minSwaps(self, grid: list[list[int]]) -> int: + n=len(grid) + ans=0 + for y in range(n): + need=n-(y+1) + target=-1 + for ny in range(y,n): + if self.is_poss(grid,ny,need): + target=ny + break + if target==-1:return -1 + while target>y: + ans+=1 + self.swap(grid,target,target-1) + target-=1 + + return ans + + diff --git "a/leetcode3/\354\230\244\354\235\200\355\230\201/1696. Jump Game VI" "b/leetcode3/\354\230\244\354\235\200\355\230\201/1696. Jump Game VI" new file mode 100644 index 00000000..f734b044 --- /dev/null +++ "b/leetcode3/\354\230\244\354\235\200\355\230\201/1696. Jump Game VI" @@ -0,0 +1,18 @@ +import heapq +class Solution: + def maxResult(self, nums: list[int], k: int) -> int: + hq=[] + dp=[0]*len(nums) + dp[0]=nums[0] + heapq.heappush(hq,(-dp[0],0)) + for i in range(1,len(nums)): + while hq and hq[0][1]