Algorithm/Leetcode, Lintcode, HackerRank, etc.(25)
-
2409. Count Days Spent Together
Intuition this problem is easy. so, the day of arrive and leave are limited in the same year! so, simplely find out the leave day of the year and the arrive day of the year for both Alice and Bob. And then find the latest arrive day and the earliest leave day. If the leave day is bigger than or equal to the arrive day, then just calculate difference between leave day and arrive day. that's the a..
2023.01.07 -
2244. Minimum Rounds to Complete All Tasks
class Solution: def minimumRounds(self, tasks: List[int]) -> int: freq = collections.Counter(tasks) cnt = 0 for num, count in freq.items(): if count = 2: if (count > 2 and count % 2 != 0) or count % 3 == 0: count -= 3 else: count -= 2 cnt += 1 return cnt
2022.05.01 -
2243. Calculate Digit Sum of a String
class Solution: def digitSum(self, s: str, k: int) -> str: while len(s) > k: i = 0 next = '' while i < len(s): next += str(sum([int(ch) for ch in s[i:min(i + k, len(s))]])) i += k s = next return s
2022.04.29 -
2248. Intersection of Multiple Arrays
class Solution: def intersection(self, nums: List[List[int]]) -> List[int]: intr = set(nums[0]) for num in nums[1:]: intr = intr & set(num) return sorted(intr)
2022.04.29 -
2138. Divide a String Into Groups of Size k
class Solution: def divideString(self, s: str, k: int, fill: str) -> List[str]: n = len(s) res = [] i = 0 while i < n: pad = k - len(s[i:i + k]) res += s[i:i + k] + fill*pad, i += k return res
2022.01.22 -
2134. Minimum Swaps to Group All 1's Together II
class Solution: def minSwaps(self, nums: List[int]) -> int: n = len(nums) ones = nums.count(1) zeros = nums[:ones].count(0) mn_zeros = zeros for i in range(n - 1): if nums[i] == 0: zeros -= 1 if nums[(i + ones)%n] == 0: zeros += 1 mn_zeros = min(mn_zeros, zeros) return mn_zeros
2022.01.09