Skip to content

Commit db1db7d

Browse files
committed
2021-03-09
1 parent d496b22 commit db1db7d

File tree

2 files changed

+20
-5
lines changed

2 files changed

+20
-5
lines changed

1556.千位分隔数/1556-千位分隔数.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,13 @@ def thousandSeparator(self, n):
44
:type n: int
55
:rtype: str
66
"""
7-
s = str(n)[::-1]
87
res = ""
9-
for i in range(len(s)):
10-
res += s[i]
11-
if i % 3 == 2 and i != len(s) - 1:
8+
cnt = 0
9+
for digit in str(n)[::-1]:
10+
res += digit
11+
cnt += 1
12+
if cnt == 3:
13+
cnt = 0
1214
res += "."
13-
return res[::-1]
15+
16+
return res[::-1].strip(".")
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
class Solution(object):
2+
def numSpecial(self, mat):
3+
"""
4+
:type mat: List[List[int]]
5+
:rtype: int
6+
"""
7+
# 找出所有满足条件的行和列
8+
possible_rows = [i for i, row in enumerate(mat) if sum(row) == 1]
9+
possible_cols = [i for i, col in enumerate(zip(*mat)) if sum(col) == 1]
10+
11+
# 在满足条件的行和列里统计值为1的点
12+
return sum([mat[i][j] for i in possible_rows for j in possible_cols])

0 commit comments

Comments
 (0)