800. Similar RGB Color

Brute Force class Solution: def similarRGB(self, color: str) -> str: res = ['#'] n = len(color) for i in range(1,n,2): cc = color[i:i+2] if cc[0] == cc[1]: res.append(cc) elif cc[0] > cc[1]: higher = cc[0]*2 lower = hex(int(cc[0],16)- int('1',16))[2]*2 higher_diff = int(higher,16)-int(cc,16) lower_diff = int(cc,16) - int(lower,16) close = lower... [Read More]
Tags: Math String

1295. Find Numbers with Even Number of Digits

Note the time complexity of str() convertion is O(len(S)) S: target string class Solution: def findNumbers(self, nums: List[int]) -> int: """tc O(N*max(len(str(num)))) sc O(1) """ res = 0 for x in nums: res += 1 - len(str(x))%2 return res [Read More]
Tags: Array

1130. Minimum Cost Tree From Leaf Values

class Solution: def mctFromLeafValues(self, A: List[int]) -> int: """" tc O(N) sc O(N) get a bigger than st[-1] value a, pop() off the smaller value b since we are not going to need it in order to make b's parent value smallest, we need to get b's neighbour small as... [Read More]
Tags: DP Stack Tree