Skip to content

Instantly share code, notes, and snippets.

View wanderindev's full-sized avatar

Javier Feliu wanderindev

View GitHub Profile
class Solution(object):
def sum_of_squares(self, n):
result = 0
while n > 0:
digit = n % 10
n = n // 10
result += digit ** 2
return result
def is_happy(self, n):
class ListNode(object):
def __init__(self, x):
self.val = x
self.next = None
class Solution(object):
def has_cycle(self, head):
"""
:type head: ListNode
class TreeNode(object):
def __init__(self, val=0, left=None, right=None):
self.val = val
self.left = left
self.right = right
class Solution(object):
def is_same_tree(self, p, q):
"""
class Solution(object):
def climb_stairs(self, n):
"""
:type n: int
:rtype: int
"""
if n == 1:
return 1
results = [0] * n
class Solution(object):
def plus_one(self, digits):
"""
:type digits: List[int]
:rtype: List[int]
"""
carry = 0
index = 0
added = False
digits = digits[::-1]
class Solution(object):
def max_subarray(self, nums):
"""
:type nums: List[int]
:rtype: int
"""
max_sum = nums[0]
curr_sum = 0
for num in nums:
class Solution:
def top_k_frequent(self, nums, k):
"""
:type nums: List[int]
:type k: int
:rtype: List[int]
"""
num_count = {}
list_of_counts = [[] for i in range(len(nums) + 1)]
results = []
class Solution:
def longest_consecutive(self, nums):
"""
:type nums: List[int]
:rtype: int
"""
longest_sequence = 0
set_of_nums = set(nums)
for num in nums:
class Solution(object):
def search(self, nums, target):
"""
:type nums: List[int]
:type target: int
:rtype: int
"""
left_pointer = 0
right_pointer = len(nums) - 1
class TreeNode(object):
def __init__(self, val=0, left=None, right=None):
self.val = val
self.left = left
self.right = right
class Solution(object):
def invert_tree(self, root):
"""