Skip to content

Instantly share code, notes, and snippets.

@ryuji0123
ryuji0123 / ABC 128-C
Last active October 5, 2019 07:41
Python script for AtCoder ABC 128-C Switches
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
@ryuji0123
ryuji0123 / LeetCode 654
Last active October 5, 2019 05:28
Python script for LeetCode 654. Maximum Binary Tree
# 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):
"""
@ryuji0123
ryuji0123 / LeetCode 1021
Created October 5, 2019 05:30
Python script for LeetCode 1021. Remove Outermost Parentheses
class Stack(object):
def __init__(self):
self.container = []
def __len__(self):
return len(self.container)
def push(self, elem):
self.container.append(elem)
@ryuji0123
ryuji0123 / ABC 129-C
Last active October 5, 2019 07:40
Python script for AtCoder ABC 129-C Typical Stairs
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
@ryuji0123
ryuji0123 / LeetCode 121
Created October 6, 2019 07:49
Python script for LeetCode 121. Best Time to Buy and Sell Stock
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]
@ryuji0123
ryuji0123 / ABC 131-C
Created October 6, 2019 09:02
Python script for AtCoder ABC 131-C Anti-Division
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:
@ryuji0123
ryuji0123 / AtCoder ABC 132-C
Created October 7, 2019 10:47
Python script for AtCoder ABC 132-C Divide the Problems
__name__ == '__main__':
N = int(input())
d = sorted([int(i) for i in input().split()])
print(d[N // 2] - d[N // 2 - 1])
@ryuji0123
ryuji0123 / LeetCode 122
Created October 7, 2019 14:48
Python script for LeetCode 122. Best Time to Buy and Sell Stock II
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:
@ryuji0123
ryuji0123 / LeetCode 238
Created October 9, 2019 08:19
Python script for LeetCode 238. Product of Array Except Self
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):
@ryuji0123
ryuji0123 / AtCoder ABC 133
Created October 9, 2019 09:29
Python script for AtCoder ABC 133 - Remainder Minimization 2019
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:]: