Skip to content

Commit 81ec8a5

Browse files
committed
no message
1 parent 98a3a80 commit 81ec8a5

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
"""
2+
Time: O(NLogN)
3+
Space: O(N)
4+
"""
5+
class Solution(object):
6+
def findOriginalArray(self, changed):
7+
if len(changed)%2!=0: return []
8+
9+
ans = []
10+
counter = collections.Counter() #store the count of the doubled number
11+
count = 0 #sum of count in counter
12+
13+
changed.sort() #need to be sorted, otherwise we cannot identify which number is orginal or it is doubled.
14+
15+
for num in changed:
16+
if counter[num]>0:
17+
#num is a doubled num
18+
counter[num] -= 1
19+
count -= 1
20+
ans.append(num/2)
21+
else:
22+
#num is an original num
23+
counter[num*2] += 1
24+
count += 1
25+
26+
return ans if count==0 else []

problems/logger-rate-limiter.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
class Logger(object):
2+
def __init__(self):
3+
self.log = collections.Counter() #store the latest timestamp
4+
5+
def shouldPrintMessage(self, timestamp, message):
6+
if message not in self.log or self.log[message]+10<=timestamp:
7+
self.log[message] = timestamp
8+
return True
9+
else:
10+
return False

0 commit comments

Comments
 (0)