Skip to content

Commit ca61818

Browse files
author
Parth
committed
Changes
1 parent d48d340 commit ca61818

File tree

2 files changed

+20
-16
lines changed

2 files changed

+20
-16
lines changed

#229_majority_element_ii.py

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,10 @@
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
1610

17-

reverse_integer.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
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))

0 commit comments

Comments
 (0)