Skip to content

Commit a3b9754

Browse files
authored
Update the-k-weakest-rows-in-a-matrix.py
1 parent f9442eb commit a3b9754

File tree

1 file changed

+4
-8
lines changed

1 file changed

+4
-8
lines changed

Python/the-k-weakest-rows-in-a-matrix.py

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,14 @@ def kWeakestRows(self, mat, k):
1515
continue
1616
lookup.add(i)
1717
result.append(i)
18-
k -= 1
19-
if not k:
18+
if len(result) == k:
2019
return result
2120
for i in xrange(len(mat)):
2221
if i in lookup:
2322
continue
2423
lookup.add(i)
2524
result.append(i)
26-
k -= 1
27-
if not k:
25+
if len(result) == k:
2826
break
2927
return result
3028

@@ -47,15 +45,13 @@ def kWeakestRows(self, mat, k):
4745
if mat[i][j] or i in lookup:
4846
continue
4947
lookup[i] = True
50-
k -= 1
51-
if not k:
48+
if len(lookup) == k:
5249
return lookup.keys()
5350
for i in xrange(len(mat)):
5451
if i in lookup:
5552
continue
5653
lookup[i] = True
57-
k -= 1
58-
if not k:
54+
if len(lookup) == k:
5955
break
6056
return lookup.keys()
6157

0 commit comments

Comments
 (0)