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 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 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 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 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
# 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] |
OlderNewer