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 find132pattern(self, nums): | |
intervals = [[nums[0]]] | |
for i in range(1, len(nums)): | |
if nums[i] < nums[i-1]: | |
intervals[-1].append(nums[i-1]) | |
intervals.append([nums[i]]) | |
for inter in intervals[:-1]: | |
low, high = inter | |
if low < nums[i] < high: | |
return 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 last_remaining(n): | |
arr=list(range(1,n+1)) | |
while len(arr) != 1: | |
slice_from=1 if len(arr) % 2 ==1 or start_to_end else 0 | |
arr=arr[slice_from::2] | |
start_to_end = not start_to_end | |
return arr.pop() | |
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_in_pairs(n): | |
if n<10: | |
return n | |
last_dig=n%10 | |
before_last= (n%100)//10 | |
return 100*flip_in_pairs(n//100)+last_dig*10+befor_last |
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,num): | |
res=0 | |
for n in num: | |
res ^= n | |
return res |