def lower_bound(input_list, target_value): if not input_list: return 0 lo, hi = 0, len(input_list) while lo < hi: mid = (lo + hi) // 2 if input_list[mid] < target_value: lo = mid + 1 else: hi = mid return lo def upper_bound(input_list, target_value): if not input_list: return 0 lo, hi = 0, len(input_list) while lo < hi: mid = (lo + hi) // 2 if target_value < input_list[mid]: hi = mid else: lo = ..
Shuffle an Array - LeetCode Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview. leetcode.com class Solution: def __init__(self, nums: List[int]): def reset(self) -> List[int]: """ Resets the array to its original configuration and return it. """ def shuffle(self) -> List[int]: """ Returns a random shuffling..
4Sum II - LeetCode Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview. leetcode.com 1. 틀림 from typing import * class Solution: def fourSumCount(self, nums1: List[int], nums2: List[int], nums3: List[int], nums4: List[int]) -> int: set1, set2 = set(), set() for num1 in nums1: for num2 in nums2: set1.add(num1 ..
Flatten Nested List Iterator - LeetCode Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview. leetcode.com # """ # This is the interface that allows for creating nested lists. # You should not implement it, or speculate about its implementation # """ #class NestedInteger: # def isInteger(self) -> bool: # """ ..
Factorial Trailing Zeroes - LeetCode Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview. leetcode.com 1. 틀린 풀이 class Solution: def trailingZeroes(self, n: int) -> int: return n // 5 N이 주어지고 N! 의 0의 개수를 반환하는 문제다. 처음에는 DP 인가라고 생각을 했다가 좀 더 쉽게 생각할 수 있는 문제인 것 같았다. 0이 만들어지려면 10이 곱해져야 한다. 그리고 10은 2와 5의 곱이다. 즉 2와 5..
Valid Palindrome - LeetCode Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview. leetcode.com 1. isalnum() class Solution: def isPalindrome(self, s: str) -> bool: stack = [] for char in s: if char.isalnum(): stack.append(char.lower()) if len(stack) % 2 == 1: return stack[:len(stack) // 2] == stack[len(stack)..