Skip to content

Commit

Permalink
2019-12-01
Browse files Browse the repository at this point in the history
  • Loading branch information
JiayangWu committed Dec 2, 2019
1 parent 90cb0fa commit 11153bd
Show file tree
Hide file tree
Showing 3 changed files with 89 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
class Solution(object):
def tictactoe(self, moves):
"""
:type moves: List[List[int]]
:rtype: str
"""
grid = [[-1 for _ in range(3)] for _ in range(3)]
def check():
for row in grid:
if row == [0, 0, 0]:
return 0
if row == [1, 1, 1]:
return 1

for j in range(3):
tmp = []
for i in range(3):
tmp.append(grid[i][j])
if tmp == [0, 0, 0]:
return 0
if tmp == [1, 1, 1]:
return 1

tmp = [grid[0][0], grid[1][1], grid[2][2]]
if tmp == [0, 0, 0]:
return 0
if tmp == [1, 1, 1]:
return 1

tmp = [grid[2][0], grid[1][1], grid[0][2]]
if tmp == [0, 0, 0]:
return 0
if tmp == [1, 1, 1]:
return 1
return -1


player = 0
for move in moves:
grid[move[0]][move[1]] = player
player = 1 - player

tmp = check()
if tmp != -1:
return "A" if tmp == 0 else "B"
return "Draw" if len(moves) == 9 else "Pending"


Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
class Solution(object):
def numOfBurgers(self, tomatoSlices, cheeseSlices):
"""
:type tomatoSlices: int
:type cheeseSlices: int
:rtype: List[int]
"""
doublex = tomatoSlices - cheeseSlices * 2
if doublex < 0 or doublex % 2 != 0:
return []

x = doublex // 2
y = cheeseSlices - doublex // 2
if x >= 0 and y >= 0:
return [x, y]
return []
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
class Solution(object):
def countSquares(self, matrix):
"""
:type matrix: List[List[int]]
:rtype: int
"""
m, n = len(matrix), len(matrix[0])
res = 0
dp = [[0 for _ in range(n)] for _ in range(m)]
for i in range(m):
dp[i][0] = matrix[i][0]
res += dp[i][0]

for j in range(1, n):
dp[0][j] = matrix[0][j]
res += dp[0][j]

for i in range(1, m):
for j in range(1, n):
if matrix[i][j]:
dp[i][j] = min(dp[i - 1][j], dp[i - 1][j - 1], dp[i][j - 1]) + 1
res += dp[i][j]
print dp
return res

0 comments on commit 11153bd

Please sign in to comment.