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): | |
n = len(nums) | |
if n < 3: | |
return False | |
min_left = [0] * n | |
min_left[0] = nums[0] | |
for i in range(1, n): | |
min_left[i] = min(min_left[i-1], nums[i]) | |
for j in range(1, n - 1): |
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 last_remaining(n): | |
head = 1 | |
step = 1 | |
left = True | |
remaining = n | |
while remaining > 1: | |
if left or remaining % 2 == 1: | |
head += step | |
step *= 2 | |
remaining //= 2 |
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 swap_pairs_from_end(n: int) -> int: | |
neg = n < 0 | |
n = -n if neg else n | |
def rec(x: int) -> int: | |
if x < 10: | |
return x | |
hi = x // 100 | |
a = (x // 10) % 10 | |
b = x % 10 |
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: | |
ans = 0 | |
for i in range(32): | |
bit_sum = 0 | |
for num in nums: | |
bit_sum += (num >> i) & 1 | |
if bit_sum % 3: | |
ans |= (1 << i) | |
return ans if ans < (1 << 31) else ans - (1 << 32) |