LC link
Maintain a deque to
1. line 23, convert to float and make sure divisor is not zero
1. line 1 import collections
2. line 5 declare deque with maxlen by collections.deque(maxlen = size)
Thursday, August 17, 2017
[Leetcode] Meeting Rooms I and II
LC link1
Sort based on start time and check conflicts
1. Line 7,8 old drill, valid inputs
2. Line 10, sort element in place based on object's attribute python programming sugar
3. Line 12, how to handle the case where len(intervals) == 1
Use for i in xrange( 1, len(intervals)) It will ignore the case where len(intervals) == 1
LC link
Create sorted start/end list, use rooms/end_pointer trick to iterate through
1. Line 20, should be smaller, cuz start time == end time, it means a room is released
2. Line 20, don't forget to use end_pointer
3. Line 22, 23, it means a new room is release, don't need a new room, but move end_pointer
Sort based on start time and check conflicts
1. Line 7,8 old drill, valid inputs
2. Line 10, sort element in place based on object's attribute python programming sugar
3. Line 12, how to handle the case where len(intervals) == 1
Use for i in xrange( 1, len(intervals)) It will ignore the case where len(intervals) == 1
LC link
Create sorted start/end list, use rooms/end_pointer trick to iterate through
1. Line 20, should be smaller, cuz start time == end time, it means a room is released
2. Line 20, don't forget to use end_pointer
3. Line 22, 23, it means a new room is release, don't need a new room, but move end_pointer
[Leetcode]Binary Tree Level Order Traversal (AKA BFS)
LC link
Push root to queue then traverse level by level
1. Line 7, 8, old drill, validate input and ask what they want if input is not valid
2. Line 13, use for loop to simulate level by level visiting
3. line 12, 15, 20, know what they want for output,
4. Line 14, queue, FIFO pop(0) stack FILO pop()
Push root to queue then traverse level by level
1. Line 7, 8, old drill, validate input and ask what they want if input is not valid
2. Line 13, use for loop to simulate level by level visiting
3. line 12, 15, 20, know what they want for output,
4. Line 14, queue, FIFO pop(0) stack FILO pop()
[Leetcode]Number of Islands
LC link
Summary:
Ignore boundaries, sink method handles all logic and sink up/down left/right
1. Line 14, old drill, when I wrote line 14, i and j could not be negative, but in line 17,18, we access i - 1, j - 1, we need to check whether i and j are negative. Always check validness of objects or index.
Test case ["1011011"]
2. Line 17, 18 Whenever create or change method signature, check signatures!
3.
# 000
# 010
# 000 is a valid island
4. 0 == '0' returns False
5. Line 14, 17, 18 our approach ignores values on edges. So we need to sink up, down, left ,right whenever we find a island
["111","010","111"] for example, case like that
Summary:
Ignore boundaries, sink method handles all logic and sink up/down left/right
1. Line 14, old drill, when I wrote line 14, i and j could not be negative, but in line 17,18, we access i - 1, j - 1, we need to check whether i and j are negative. Always check validness of objects or index.
Test case ["1011011"]
2. Line 17, 18 Whenever create or change method signature, check signatures!
3.
# 000
# 010
# 000 is a valid island
4. 0 == '0' returns False
5. Line 14, 17, 18 our approach ignores values on edges. So we need to sink up, down, left ,right whenever we find a island
["111","010","111"] for example, case like that
6. let sink method takes care of input check and most of logics
[Leetcode]Add Two Numbers
LC Link
1. line 11, use while loop controls on 11, l2 and carry
2. line 13,16, take care of l1 and l2 separately. Cuz you always want to check Nullness before you access its attributes.
3. line 21, use carry, curr_val = divmod(raw_num, 10) to speed up process
4. line 9,22, be clear on the requirement. output as problems wanted
2. line 13,16, take care of l1 and l2 separately. Cuz you always want to check Nullness before you access its attributes.
3. line 21, use carry, curr_val = divmod(raw_num, 10) to speed up process
4. line 9,22, be clear on the requirement. output as problems wanted
[Leetcode]Excel Sheet Column Number
LC Link
1. Line 11, make sure they are all upper case cuz that's our assumption that we will process upper case
2. Line 12, whenever deal with problem to convert bla bla to another number. just use same template
res = res * (10 or 8 or 26 or whatever) + value on current digit value
You don't need to consider most right digit value cuz res equals zero at very beginning
2. Line 12, whenever deal with problem to convert bla bla to another number. just use same template
res = res * (10 or 8 or 26 or whatever) + value on current digit value
You don't need to consider most right digit value cuz res equals zero at very beginning
Subscribe to:
Comments (Atom)