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
import numpy as np | |
def countMatchedSwitch(sw_status, switch, index): | |
ret = 0 | |
for s in switch[index]: | |
if int(sw_status[int(s) - 1]) == 1: | |
ret += 1 | |
return ret % 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
# Definition for a binary tree node. | |
class TreeNode(object): | |
def __init__(self, x): | |
self.val = x | |
self.left = None | |
self.right = None | |
class Solution(object): | |
def constructMaximumBinaryTree(self, nums): | |
""" |
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 Stack(object): | |
def __init__(self): | |
self.container = [] | |
def __len__(self): | |
return len(self.container) | |
def push(self, elem): | |
self.container.append(elem) | |
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
BASE = 1000000007 | |
if __name__ == '__main__': | |
N, M = [int(i) for i in input().split()] | |
not_available = [] | |
for i in range(M): | |
not_available.append(int(input())) | |
x = 0 | |
y = 1 | |
predicted_next = 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
class Solution(object): | |
def maxProfit(self, prices): | |
""" | |
:type prices: List[int] | |
:rtype: int | |
""" | |
if len(prices) == 0: | |
return 0 | |
max_profit = 0 | |
min_price = prices[0] |
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 getDivisableCount(min_bound, max_bound, div): | |
return max_bound // div - (min_bound - 1) // div | |
def LCM(a, b): | |
return a * b // GCD(a, b) | |
def GCD(a, b): | |
if a > b: | |
a, b = b, a | |
while b % a != 0: |
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
__name__ == '__main__': | |
N = int(input()) | |
d = sorted([int(i) for i in input().split()]) | |
print(d[N // 2] - d[N // 2 - 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
class Solution(object): | |
def maxProfit(self, prices): | |
""" | |
:type prices: List[int] | |
:rtype: int | |
""" | |
if len(prices) == 0: | |
return 0 | |
i = 0 | |
while i < len(prices) - 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
class Solution(object): | |
def productExceptSelf(self, nums): | |
""" | |
:type nums: List[int] | |
:rtype: List[int] | |
""" | |
mul = 1 | |
right_side_mul = [] | |
left_side_mul = [] | |
for num in reversed(nums): |
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
div = 2019 | |
if __name__ == '__main__': | |
L, R = [int(i) for i in input().split()] | |
if R - L > div - 1: | |
R = L + div - 1 | |
number_ref = [num for num in range(L, R + 1, 1)] | |
min_mod = 2018 | |
for idx, i in enumerate(number_ref): | |
for j in number_ref[idx + 1:]: |
OlderNewer