This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Solution(object): | |
def diffWaysToCompute(self, input): | |
memo = {} | |
return self.buildTrees(input, memo) | |
def buildTrees(self, s, memo): | |
if s in memo: | |
return memo[s] | |
response = [] | |
isOperand = True |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Solution: | |
def removeVowels(self, S: str) -> str: | |
vowels = ['a', 'e', 'i', 'o', 'u'] | |
result = "" | |
for x in S: | |
if x not in vowels: | |
result += x | |
return result |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# https://leetcode.com/explore/challenge/card/30-day-leetcoding-challenge/528/week-1/3283/ | |
class Solution: | |
def singleNumber(self, nums: List[int]) -> int: | |
result = 0 | |
for number in nums: | |
result ^= number | |
return result |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# https://leetcode.com/explore/featured/card/30-day-leetcoding-challenge/528/week-1/3284/ | |
class Solution: | |
def isHappy(self, n: int) -> bool: | |
knownNumbers = {} | |
while True: | |
if n == 1: | |
return True | |
if n in knownNumbers: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# https://leetcode.com/explore/featured/card/30-day-leetcoding-challenge/528/week-1/3285/ | |
class Solution: | |
def maxSubArray(self, nums: List[int]) -> int: | |
maxi = nums[0] | |
tempSum = nums[0] | |
for n in nums[1:]: | |
if tempSum < 0: | |
tempSum = n | |
else: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Solution: | |
def moveZeroes(self, nums: List[int]) -> None: | |
def swap(a: int, b: int, nums: List[int]) -> None: | |
temp = nums[a] | |
nums[a] = nums[b] | |
nums[b] = temp | |
lastNonZeroPos = 0 | |
for i in range(len(nums)): | |
if nums[i] != 0: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# https://leetcode.com/explore/featured/card/30-day-leetcoding-challenge/528/week-1/3287/ | |
class Solution: | |
def maxProfit(self, prices: List[int]) -> int: | |
profit = 0 | |
for i in range(1, len(prices)): | |
if prices[i] > prices[i- 1]: | |
profit += prices[i] - prices[i - 1] | |
return profit |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# https://leetcode.com/explore/featured/card/30-day-leetcoding-challenge/528/week-1/3288/ | |
from collections import defaultdict | |
class Solution: | |
def groupAnagrams(self, strs: List[str]) -> List[List[str]]: | |
anagrams = defaultdict(list) | |
for s in strs: | |
anagrams[str(sorted(s))].append(s) | |
return anagrams.values() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import unittest | |
class Program: | |
def maxSubArrayWithKElements(self, array, k): | |
j = len(array) - k | |
currSum = minSum = sum(i for i in array[:j]) | |
for i in range(j, len(array)): | |
currSum += array[i] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# https://leetcode.com/explore/challenge/card/30-day-leetcoding-challenge/528/week-1/3289/ | |
class Solution: | |
def countElements(self, arr: List[int]) -> int: | |
s = set(arr) | |
c = 0 | |
for n in arr: | |
if n + 1 in s: | |
c += 1 | |
return c |
OlderNewer