This file contains hidden or 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 find132pattern(self, nums: List[int]) -> bool: | |
if len(nums) < 3: | |
return False | |
stack = [] | |
min_array = [-1] * len(nums) | |
min_array[0] = nums[0] | |
for i in range(1, len(nums)): | |
min_array[i] = min(min_array[i - 1], nums[i]) |
This file contains hidden or 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 lastRemaining(self, n: int) -> int: | |
def helper(n, ste=True): | |
if n == 1: | |
return n | |
return 2 * helper(n // 2, not ste) - (0 if ste or n & 1 else 1) | |
return helper(n, True) |
This file contains hidden or 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
def lengthOfLIS(self, nums: List[int]) -> int: | |
dp = [1] * len(nums) | |
for i in range(1, len(nums)): | |
longest = 0 | |
for j in range(i): | |
if nums[j] < nums[i]: | |
longest = max(longest, dp[j]) | |
dp[i] = longest + 1 | |
return max(dp) |
This file contains hidden or 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
def flip_pairs(num): | |
if num < 0: | |
return -flip_pairs(-num) | |
if num < 10: | |
return num | |
last_two = num % 100 | |
ones, tens = last_two % 10, last_two // 10 | |
return 100 * flip_pairs(num // 100) + 10 * ones + tens |
This file contains hidden or 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 singleNumber(self, nums: List[int]) -> int: | |
pos_res = neg_res = 0 | |
for bit in range(32): | |
pos_cnt = neg_cnt = 0 | |
for num in nums: | |
if num > 0 and (1 << bit) & num: | |
pos_cnt += 1 | |
if num < 0 and (1 << bit) & -num: |