#time O(lgN) space O(1) class Solution: def nthUglyNumber(self, n: int, a: int, b: int, c: int) -> int: max_val = 2*10**9 l = 1 r = max_val #step1 gcd def gcd(a,b): if b == 0: return a else: return gcd(b, a%b) #step 2 lcm def lcm(a,b): return a*b//gcd(a,b) # step3...
[Read More]
Lc1150
LC1190 Reverse Substrings Between Each Pair of Parentheses
You are given a string s that consists of lower case English letters and brackets.
[Read More]
LC207 Course Schedule
class Solution: def canFinish(self, numCourses: int, prerequisites: List[List[int]]) -> bool: """ main idea: BFS keep tracking of indegree, push into queue when in degree == 0 tc O(V+E) sc O(V+E) """ # (1)one node can direct to multiple node (2) there are isolated nodes (3) no circle # can't use...
[Read More]
LC278 First Bad Version
You are a product manager and currently leading a team to develop a new product. Unfortunately, the latest version of your product fails the quality check. Since each version is developed based on the previous version, all the versions after a bad version are also bad.
[Read More]