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
// 217. Contains Duplicate | |
// Easy | |
// Given an integer array nums, return true if any value appears at least twice in the array, and return false if every element is distinct. | |
const containsDuplicate = (nums) => { | |
// create an empty dictionary | |
// iterate through the array | |
// for each integer in the array check if the integer position exists in the dictionary | |
// if 'yes' 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
from itertools import combinations | |
def minDifference(wakeTimes): | |
# if wakeTimes is an empty array | |
if not wakeTimes: | |
return 0 | |
# creates an array of wakeTimes in minute | |
wakeTimesInMins = list(map( lambda x: int(x[0]) * 60 + int(x[1]), [ time.split(":") for time in wakeTimes ])) |
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
from collections import deque | |
def shuffleClass(listOfPupils, n): | |
#test if listOfPupils is a list, has none value or empty | |
if (not isinstance(listOfPupils, list)) or (not listOfPupils): | |
return [] | |
#takes the last 'n' items to the front using 'deque' | |
else: |
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 prodOfNums(nums): | |
if len(nums) == 0: | |
return "invalid array: input an array of numbers" | |
else: | |
prod = 1 | |
ans = [] | |
for i in nums: | |
prod *= i | |
for i in range(0,len(nums)): | |
ans.append(prod // nums[i]) |
NewerOlder