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 1919
2020from typing import List
2121
22+
2223class Solution :
2324 def countBits (self , n : int ) -> List [int ]:
24-
2525 output = []
26- for i in range (n + 1 ):
26+ for i in range (n + 1 ):
2727 _str = str (bin (i ))[2 :]
2828 _sum = sum (map (int , _str .strip ()))
2929 output .append (_sum )
3030
31- return output
31+ return output
Original file line number Diff line number Diff line change 2626
2727from typing import List
2828
29+
2930class Solution :
3031 def groupAnagrams (self , strs : List [str ]) -> List [List [str ]]:
31-
3232 hash_table = []
3333 counters = []
3434 for s in strs :
35-
36- count_s = '' .join (sorted (s ))
35+ count_s = "" .join (sorted (s ))
3736 if count_s in hash_table :
3837 idx = hash_table .index (count_s )
3938 counters [idx ].append (s )
4039 else :
4140 hash_table .append (count_s )
4241 counters .append ([s ])
43-
42+
4443 return counters
Original file line number Diff line number Diff line change 1818"""
1919from typing import List
2020
21+
2122class Solution :
2223 def missingNumber (self , nums : List [int ]) -> int :
23-
2424 nums .sort ()
2525 for i in range (len (nums )):
2626 if i != nums [i ]:
2727 return i
2828
2929 return len (nums )
30-
Original file line number Diff line number Diff line change 1616 - No extra space is used
1717"""
1818
19+
1920class Solution :
2021 def hammingWeight (self , n : int ) -> int :
2122 output = 0
2223
2324 i = 1 << 31
24- while (i > 0 ) :
25-
26- if ((n & i ) != 0 ) :
25+ while i > 0 :
26+ if (n & i ) != 0 :
2727 output += 1
28-
28+
2929 i = i // 2
3030
31- return output
31+ return output
Original file line number Diff line number Diff line change 1818
1919"""
2020
21+
2122class Solution :
2223 def reverseBits (self , n : int ) -> int :
2324 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