File tree Expand file tree Collapse file tree 5 files changed +15
-16
lines changed Expand file tree Collapse file tree 5 files changed +15
-16
lines changed Original file line number Diff line number Diff line change 19
19
20
20
from typing import List
21
21
22
+
22
23
class Solution :
23
24
def countBits (self , n : int ) -> List [int ]:
24
-
25
25
output = []
26
- for i in range (n + 1 ):
26
+ for i in range (n + 1 ):
27
27
_str = str (bin (i ))[2 :]
28
28
_sum = sum (map (int , _str .strip ()))
29
29
output .append (_sum )
30
30
31
- return output
31
+ return output
Original file line number Diff line number Diff line change 26
26
27
27
from typing import List
28
28
29
+
29
30
class Solution :
30
31
def groupAnagrams (self , strs : List [str ]) -> List [List [str ]]:
31
-
32
32
hash_table = []
33
33
counters = []
34
34
for s in strs :
35
-
36
- count_s = '' .join (sorted (s ))
35
+ count_s = "" .join (sorted (s ))
37
36
if count_s in hash_table :
38
37
idx = hash_table .index (count_s )
39
38
counters [idx ].append (s )
40
39
else :
41
40
hash_table .append (count_s )
42
41
counters .append ([s ])
43
-
42
+
44
43
return counters
Original file line number Diff line number Diff line change 18
18
"""
19
19
from typing import List
20
20
21
+
21
22
class Solution :
22
23
def missingNumber (self , nums : List [int ]) -> int :
23
-
24
24
nums .sort ()
25
25
for i in range (len (nums )):
26
26
if i != nums [i ]:
27
27
return i
28
28
29
29
return len (nums )
30
-
Original file line number Diff line number Diff line change 16
16
- No extra space is used
17
17
"""
18
18
19
+
19
20
class Solution :
20
21
def hammingWeight (self , n : int ) -> int :
21
22
output = 0
22
23
23
24
i = 1 << 31
24
- while (i > 0 ) :
25
-
26
- if ((n & i ) != 0 ) :
25
+ while i > 0 :
26
+ if (n & i ) != 0 :
27
27
output += 1
28
-
28
+
29
29
i = i // 2
30
30
31
- return output
31
+ return output
Original file line number Diff line number Diff line change 18
18
19
19
"""
20
20
21
+
21
22
class Solution :
22
23
def reverseBits (self , n : int ) -> int :
23
24
n_bin = bin (n )[2 :].zfill (32 )
24
- n_bin = '' .join (reversed (n_bin ))
25
- return int (n_bin , base = 2 )
25
+ n_bin = "" .join (reversed (n_bin ))
26
+ return int (n_bin , base = 2 )
You can’t perform that action at this time.
0 commit comments