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
# Definition for an interval. | |
# class Interval(object): | |
# def __init__(self, s=0, e=0): | |
# self.start = s | |
# self.end = e | |
class Solution(object): | |
def merge(self, intervals): | |
""" | |
:type intervals: List[Interval] |
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(object): | |
def groupAnagrams(self, strs): | |
""" | |
:type strs: List[str] | |
:rtype: List[List[str]] | |
""" | |
from itertools import groupby | |
sortedAnagrams = sorted(sorted(strs), key=lambda a: sorted(a)) | |
return [list(v) for k,v in groupby(sortedAnagrams, key=lambda a: sorted(a))] |
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(object): | |
def isHappy(self, n): | |
""" | |
:type n: int | |
:rtype: bool | |
""" | |
seenNums = set() | |
while n > 1 and (n not in seenNums): | |
seenNums.add(n) | |
n = sum(map(lambda x: x**2, map(int, list(str(n))))) |
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(object): | |
def findPeakElement(self, nums): | |
""" | |
:type nums: List[int] | |
:rtype: int | |
""" | |
return self.findPeakRecur(nums, 0, len(nums)-1) | |
def findPeakRecur(self, nums, lo, hi): | |
mid = (lo + hi) // 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
#include <cmath> | |
#include <vector> | |
class TurretDefense { | |
public: | |
int firstMiss(std::vector <int>xs, std::vector <int>ys, std::vector <int> times) { | |
int curx = 0; | |
int cury = 0; | |
int curtime = 0; | |
for(int i = 0; i < xs.size(); i++) { |
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 { | |
public: | |
void merge(int A[], int m, int B[], int n) { | |
int i = m - 1; | |
int j = n - 1; | |
int k = m + n - 1; | |
while(i >= 0 && j >= 0) { | |
if (A[i] > B[j]) { | |
A[k--] = A[i--]; |
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: | |
# @return an integer | |
def lengthOfLongestSubstring(self, s): | |
if s is None or len(s) == 0: | |
return 0 | |
i, maxLen = 0, 0 | |
seenVals = set() # seen characters | |
for j in range(len(s)): |
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 digits, a list of integer digits | |
# @return a list of integer digits | |
def plusOne(self, digits): | |
for i in reversed(range(len(digits))): | |
digits[i] = (digits[i] + 1) % 10 | |
if digits[i] == 0: | |
continue | |
return digits | |
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
Element *findMToLastElement( Element *head, int m ) { | |
if (!head || n < 0) { | |
return NULL; | |
} | |
Element *first, *second = head, head; | |
for(int i = 0; i < m; i++) { | |
first = first->next; | |
if (!first) { | |
return NULL; | |
} |
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, a list of integers | |
# @param target, an integer to be inserted | |
# @return integer | |
def searchInsert1(self, A, target): | |
for i,val in enumerate(A): | |
if target <= val: | |
return i | |
return len(A) |
NewerOlder