Skip to content

Commit

Permalink
contest 158
Browse files Browse the repository at this point in the history
  • Loading branch information
Azureki committed Oct 13, 2019
1 parent 79c4bbd commit c07d334
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
12 changes: 12 additions & 0 deletions 1221. Split a String in Balanced Strings/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
class Solution:
def balancedStringSplit(self, s: str) -> int:
res = 0
flag = 0
for c in s:
if c == 'L':
flag += 1
else:
flag -= 1
if flag == 0:
res += 1
return res
18 changes: 18 additions & 0 deletions 1222. Queens That Can Attack the King/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
class Solution:
def queensAttacktheKing(self, queens: List[List[int]], king: List[int]) -> List[List[int]]:
res = []
dirs = [(0, 1), (0, -1), (1, 0), (-1, 0),
(1, 1), (-1, -1), (1, -1), (-1, 1)]
queens_set = set(tuple(queen) for queen in queens)
for d in dirs:
x, y = king
while True:
x, y = x + d[0], y + d[1]
if 0 <= x < 8 and 0 <= y < 8:
if (x, y) in queens_set:
res.append([x, y])
break
else:
break

return res

0 comments on commit c07d334

Please sign in to comment.