Skip to content

Commit d48d340

Browse files
author
Parth
committed
2 parents 9a1705e + 703cdf8 commit d48d340

File tree

3 files changed

+29
-0
lines changed

3 files changed

+29
-0
lines changed

#229_majority_element_II.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
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
10+
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
class Solution(object):
2+
def firstUniqChar(self, s):
3+
counter=collections.Counter(s)
4+
for char in s:
5+
if counter[char]==1:
6+
return s.index(char)
7+
return -1

451_Sort Characters By Frequency.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
class Solution(object):
2+
def frequencySort(self, s):
3+
hash={}
4+
mystring=""
5+
for char in s:
6+
hash[char]=hash.get(char,0)+1
7+
x_sorted=sorted(hash.items(), key=operator.itemgetter(1),reverse=True)
8+
sorted_dict = collections.OrderedDict(x_sorted)
9+
for k,v in sorted_dict.items():
10+
for i in range(v):
11+
mystring+=str(k)
12+
return mystring

0 commit comments

Comments
 (0)