Recently I have been playing GameStudio franchise and found their default code editor annoying, mainly because I am too comfortable with using my Sublime (with Vim) to do most kind

## [Esoteric Programming Language] RightTime

Introduction Motivation We all know that the best time to do your homework is right before its due. However, the behavior of wait until the right time to do your homework

## [LeetCode] (366) Find Leaves of Binary Tree

Source Basic Idea: since we strip one layer of leaves at a time, the time when a middle node got stripped is based on the height of its taller children

## [LeetCode] (463) Island Perimeter

Basic Idea: for each cell, add the number of legal sides to the solution.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
class Solution(object): def islandPerimeter(self, grid): """ :type grid: List[List[int]] :rtype: int """ if not grid: return 0 def sum_adjacent(i, j): adjacent = (i + 1, j), (i - 1, j), (i, j + 1), (i, j - 1), res = 0 for x, y in adjacent: if x < 0 or y < 0 or x == len(grid) or y == len(grid[0]) or grid[x][y] == 0: res += 1 return res count = 0 for i in range(len(grid)): for j in range(len(grid[0])): if grid[i][j] == 1: count += sum_adjacent(i, j) return count |

Time Complexity is .

## [LeetCode] (459) Repeated Substring Pattern

Basic Idea: try to obtain the original string using all possible repeated substring from the shortest to the longest.

1 2 3 4 5 6 7 8 9 10 |
class Solution(object): def repeatedSubstringPattern(self, str): """ :type str: str :rtype: bool """ for i in range(1, len(str) / 2 + 1): if len(str) % i == 0 and len(str) / i * str[:i] == str: return True return False |

Time Complexity is

## [LeetCode] (455) Assign Cookies

Basic idea: using a greedy algorithm, prioritize satisfying kids with lower greed and assign cookies this way as many as possible. Implementation Apple:

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
class Solution(object): def findContentChildren(self, g, s): """ :type g: List[int] :type s: List[int] :rtype: int """ g.sort() s.sort() count = 0 start = 0 for greed in g: for i, size in enumerate(s[start:]): if size >= greed: count += 1 start += i + 1 break return count |

Time Complexity is . Implementation