This file contains 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
#!/bin/python3 | |
import math | |
import os | |
import random | |
import re | |
import sys | |
# | |
# Complete the 'countingValleys' function below. |
This file contains 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
#!/bin/python3 | |
import math | |
import os | |
import random | |
import re | |
import sys | |
from collections import Counter | |
This file contains 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
""" | |
5,7,7,8,8,10 | |
n = 6 | |
first = 0 | |
last = 6 | |
mid = 0 + 6 // 2 = 3 | |
nums[mid] == 8 ? | |
""" |
This file contains 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 binarySearch(nums, target, first, last): | |
while first <= last: | |
mid = first + (last - first) // 2 | |
if nums[mid] == target: | |
return mid | |
elif nums[mid] > target: | |
last = mid - 1 | |
else: |
This file contains 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 MyQueue(object): | |
def __init__(self): | |
self.stack1 = [] | |
self.stack2 = [] | |
def peek(self): | |
if not self.stack2: | |
while self.stack1: | |
self.stack2.append(self.stack1.pop()) | |
return self.stack2[-1] |
This file contains 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 primality(n): | |
if n == 2: | |
return "Prime" | |
if n < 2 or n % 2 == 0: | |
return "Not prime" | |
limit = int(math.sqrt(n)+ 1) | |
for i in range(3,limit, 2): |
This file contains 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 removeDuplicates(self, nums: List[int]) -> int: | |
k = 0 | |
n = len(nums) | |
for i in range(1, n): | |
if nums[i] != nums[i - 1]: | |
nums[k] = nums[i - 1] | |
k += 1 | |
nums[k] = nums[n - 1] | |
k += 1 | |
return k |
This file contains 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 maxSubArray(self, nums: List[int]) -> int: | |
""" | |
-2,1,-3,4,-1,2,1,-5,4 | |
l = -2 | |
c = 1 | |
l = 1 | |
c = 1 - 3 = -2 | |
c = 0 | |
c = 4 |
This file contains 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: | |
""" | |
6,5,3,0-2-3 | |
""" | |
def maxp3(self, A): | |
A.sort(reverse=True) | |
n = len(A) | |
return max(A[0] * A[1] * A[2], A[n-1] * A[n-2]* A[0]) |
This file contains 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: | |
# @param A : tuple of integers | |
# @return an integer | |
def maximumGap(self, A): | |
n = len(A) | |
nums = [] | |
for item in enumerate(A): | |
nums.append(item) |
OlderNewer