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 highestSum(arr, k): | |
highest_sum = float('-inf') | |
n = len(arr) | |
# n must not be smaller than k | |
if n < k: | |
return -1 | |
# subarray starts at i | |
for i in range(n - k + 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 highestSum(arr, k): | |
highest_sum = float('-inf') | |
n = len(arr) | |
# n must not be smaller than k | |
if n < k: | |
return -1 | |
# Compute sum of first window of size k | |
window_sum = sum([arr[i] for i in range(k)]) |
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 isNumber(self, s): | |
""" | |
:type s: str | |
:rtype: bool | |
""" | |
#define state transition tables | |
states = [ | |
# no State (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
class Solution(object): | |
def myAtoi(self, str): | |
""" | |
:type str: str | |
:rtype: int | |
""" | |
def in_range(num): | |
if num > 2 ** 31 - 1: return 2 ** 31 - 1 | |
if num < -2**31: return -2**31 |
NewerOlder