Skip to content

Instantly share code, notes, and snippets.

@lealLuo
lealLuo / Leetcode Practice
Last active July 26, 2018 14:31
URL:https://leetcode.com/problems/flipping-an-image/description/ I made a big mistake here in Python. I use ListCopy = ListOrigin to copy the List, then change the value in ListOrigin with the value of copy version. But in python, If I simply use *Li
class Solution:
def flipAndInvertImage(self, A):
"""
:type A: List[List[int]]
:rtype: List[List[int]]
"""
def invert(value):
if value==1:
return 0
else:
@lealLuo
lealLuo / leetcode practice.py
Last active July 25, 2018 02:29
URL: https://leetcode.com/problems/max-increase-to-keep-city-skyline/description/ direct way to solve it. use too many loops, so the speed is slow
class Solution:
def maxIncreaseKeepingSkyline(self, grid):
"""
:type grid: List[List[int]]
:rtype: int
"""
# return skyline from Top or Bottom
def fromTop(grid):
listhori = []
@lealLuo
lealLuo / leetcode_practice.py
Last active July 23, 2018 16:04
URL: https://leetcode.com/problems/keyboard-row/description/ I write a function in a function. It's important to know the scope of the variable, and use print to test the simple code
class Solution:
def findWords(self, words):
"""
:type words: List[str]
:rtype: List[str]
"""
# judge which row the input char belongs to
def judgeRow(c):
row1 =['q','w','e','r','t','y','u','i','o','p','Q','W','E','R','T','Y','U','I','O','P']
row2 =['a','s','d','f','g','h','j','k','l','A','S','D','F','G','H','J','K','L']