{{ message }}

Instantly share code, notes, and snippets.

# Chaoyi Zha cydrobolt

Created Aug 21, 2017
155. Min Stack @ Leetcode
View min_stack.py
 class MinStack(object): def __init__(self): """ initialize your data structure here. """ self.curr_min = None self.stack = [] self.past_mins = []
Created Aug 21, 2017
513. Find Bottom Left Tree Value @ Leetcode
View bottom_left_tree_value.py
 # Definition for a binary tree node. # class TreeNode(object): # def __init__(self, x): # self.val = x # self.left = None # self.right = None class Solution(object): def findBottomLeftValue(self, root): """
Created Jul 5, 2017
228. Summary Ranges
View summary_ranges.py
 class Solution(object): def summaryRanges(self, nums): """ :type nums: List[int] :rtype: List[str] """ last_num = None ranges = [] range_left = None
Created Jul 5, 2017
55. Jump Game (Leetcode)
View jump_game.py
 class Solution(object): def canJump(self, nums): """ :type nums: List[int] :rtype: bool """ curr_could_jump = nums[0] arr_index = 0 if len(nums) == 1:
Created May 9, 2017
62. Unique Paths @ leetcode
View unique_paths.py
 # A robot is located at the top-left corner of a m x n grid (marked 'Start' in the diagram below). # The robot can only move either down or right at any point in time. The robot is trying to reach # the bottom-right corner of the grid (marked 'Finish' in the diagram below). # How many possible unique paths are there? # https://leetcode.com/problems/unique-paths from math import factorial as fac class Solution(object): def uniquePaths(self, m, n):
Last active Dec 4, 2016
Find number of concurrent users given a list of login and logout times
View concurrent_users.py
 # Given input which is vector of log entries of some online system each entry is something like (user_name, login_time, # logout_time), come up with an algorithm with outputs number of users logged in the system at each time slot in the input, # output should contain only the time slot which are in the input. For the example given below output should contain # timeslots # [ # ("Jane", 1.2, 4.5), # ("Jin", 3.1, 6.7), # ("June", 8.9, 10.3)
Created Nov 29, 2016
Delimiter String Parsing
View str_parse.py
 # Given a string, parse it and return an array of strings # e.g string="abc(edf)hij{klmn}opq[rs((t]uvw" # The delimiters are (), {}, [], in pairs. # => ["abc", "edf", "hij", "klmn", "opq", "rst", "uvw"] # Any two delimiter symbols next to each other == escaping. e.g "((" or "]]" are escaped. # If a delimiter is found inside an already existing delimeter, escape. # e.g "abc(e{df}}g)" => ["abc", "e{df}}g"] # https://www.careercup.com/question?id=5758190080753664 # Time complexity: O(N)
Created Nov 6, 2016
Rotate Array @ Leetcode
View rotate_arr.py
 class Solution(object): def rotate(self, nums, k): """ :type nums: List[int] :type k: int :rtype: void Do not return anything, modify nums in-place instead. """ start_indice = len(nums) - (k % len(nums)) shifted_arr = []
Created Nov 3, 2016
Battleships in a Board @ Leetcode
View battleships_in_a_board.py
 class Solution(object): def labelRestOfShip(self, kr, kc): try: if kc < 0 or kr < 0: return False board_item = self.board[kr][kc] if board_item == ".": return False
Created Nov 3, 2016
Reverse String @ Leetcode
View reverse_string.py
 class Solution(object): def reverseString(self, s): """ :type s: str :rtype: str """ letters = list(s) for i in xrange(0, len(letters)): ri = len(letters) - 1 - i li = i