File tree Expand file tree Collapse file tree 2 files changed +20
-16
lines changed Expand file tree Collapse file tree 2 files changed +20
-16
lines changed Original file line number Diff line number Diff line change 1
- def majorityElement (nums ):
2
- hash = {}
3
- major = []
4
- for num in nums :
5
- hash [num ]= hash .get (num ,0 )+ 1
6
- for num ,value in hash .items ():
7
- if hash [num ]> (len (nums )// 3 ):
8
- major .append (num )
9
- return major
10
-
11
-
12
- nums = [1 ,1 ,1 ,3 ,3 ,2 ,2 ,2 ]
13
- print (majorityElement (nums ))
14
-
15
-
1
+ class Solution (object ):
2
+ def majorityElement (self , nums ):
3
+ mylist = set ()
4
+ counter = collections .Counter ()
5
+ counter .update (nums )
6
+ for i in counter :
7
+ if counter [i ] > len (nums )/ 3 :
8
+ mylist .add (i )
9
+ return mylist
16
10
17
-
Original file line number Diff line number Diff line change
1
+ def reverse_integer (x ):
2
+ if x < 0 :
3
+ x = int (str (x )[::- 1 ][- 1 ] + str (x )[::- 1 ][:- 1 ])
4
+ if x >= 0 :
5
+ x = int (str (x )[::- 1 ][:])
6
+ if abs (x ) > 0x7FFFFFFF :
7
+ return 0
8
+ return x
9
+
10
+ i = - 12389589999999999999999
11
+ print (reverse_integer (i ))
You can’t perform that action at this time.
0 commit comments