This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Solution(object): | |
| def isValidSudoku(self, board): | |
| for row in range(0, 9): | |
| # col | |
| list = [0] * 10 | |
| for col in range(0, 9): | |
| if board[row][col] == '.': continue | |
| value = int(board[row][col]) | |
| if list[value] == 1: | |
| # print("col",row, col, value, list[value]) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Solution(object): | |
| def maxSatisfied(self, customers, grumpy, X): | |
| noGrumpy = 0 | |
| maxGrumpy = 0 | |
| currentGrumpy = 0 | |
| for index in range(0, X): | |
| if grumpy[index] == 1: | |
| currentGrumpy += customers[index] | |
| maxGrumpy = currentGrumpy | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Solution(object): | |
| def lemonadeChange(self, bills): | |
| coin5Count = 0 | |
| coin10Count = 0 | |
| for bill in bills: | |
| if bill == 5: | |
| coin5Count += 1 | |
| elif bill == 10: | |
| if coin5Count == 0: | |
| return False |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Solution(object): | |
| def findJudge(self, N, trust): | |
| voteList = [0] * (N+1) | |
| peopleList = [False] * (N+1) | |
| for arr in trust: | |
| people = arr[0] | |
| trusted = arr[1] | |
| peopleList[people] = True |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Solution(object): | |
| def visit(self, grid, row, col, rowMAX, colMAX): | |
| length = 0 | |
| # check up | |
| if row == 0 or grid[row-1][col] == 0: | |
| length += 1 | |
| # check down |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Solution(object): | |
| def visit(self, grid, row, col, rowMAX, colMAX): | |
| if row < 0 or row == rowMAX or col < 0 or col == colMAX: | |
| return 0 | |
| if grid[row][col] == 0 or grid[row][col] == 2: | |
| return 0 | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Solution(object): | |
| def fill(self, image, sr, sc, R, C, oldColor, newColor): | |
| if sr == R or sr < 0 or sc < 0 or sc == C: | |
| return | |
| if image[sr][sc] == newColor: | |
| return | |
| if image[sr][sc] is not oldColor: | |
| return; | |
| image[sr][sc] = newColor; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Solution(object): | |
| def fill(self, image, sr, sc, oldColor, newColor, hasVisited): | |
| # print("check", sr, sc) | |
| if sr == len(image) or sr < 0 or sc < 0 or sc == len(image[0]): | |
| return | |
| if hasVisited[sr][sc] == True: | |
| return | |
| if image[sr][sc] is not oldColor: | |
| return; | |
| # print("go", sr, sc) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| int uniquePaths(int m, int n){ | |
| int up = m + n - 2; | |
| int down = m > n ? m-1:n-1 ; | |
| double upValue = 1; | |
| double downValue = 1; | |
| int i; | |
| for(i = down + 1; i <= up; i++) | |
| upValue *= i; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| void dfs(char** grid, int rowMax, int colMax, int currentRow, int currentCol) { | |
| if (currentRow >= rowMax || currentRow < 0 || currentCol >= colMax || currentCol < 0 || grid[currentRow][currentCol] != '1') return; | |
| grid[currentRow][currentCol] = '0'; | |
| dfs(grid, rowMax, colMax, currentRow + 1, currentCol); | |
| dfs(grid, rowMax, colMax, currentRow - 1, currentCol); | |
| dfs(grid, rowMax, colMax, currentRow, currentCol + 1); | |
| dfs(grid, rowMax, colMax, currentRow, currentCol - 1); | |
| } |