File tree Expand file tree Collapse file tree 2 files changed +29
-0
lines changed Expand file tree Collapse file tree 2 files changed +29
-0
lines changed Original file line number Diff line number Diff line change
1
+ """
2
+ Time: O(1)
3
+ Space: O(1), no "extra" space are used.
4
+ """
5
+ class Solution (object ):
6
+ def readBinaryWatch (self , turnedOn ):
7
+ ans = []
8
+ if turnedOn > 8 : return ans #at most 8 LED are turned on for a valid time.
9
+
10
+ for h in xrange (12 ):
11
+ for m in xrange (60 ):
12
+ if (bin (h ) + bin (m )).count ('1' )== turnedOn :
13
+ ans .append ('%d:%02d' % (h , m ))
14
+ return ans
Original file line number Diff line number Diff line change
1
+ """
2
+ Time: O(N^2)
3
+ Space: O(N)
4
+
5
+ People need to be exactly insert to index k, so that there are "exact" k people equal or taller to k.
6
+ Shorter person does not matter (invisible) to taller person, so insert taller person first.
7
+ People does not care about the people on their right, so insert the person with smaller k first.
8
+ """
9
+ class Solution (object ):
10
+ def reconstructQueue (self , people ):
11
+ people .sort (key = lambda x : (- x [0 ], x [1 ]))
12
+ ans = []
13
+ for h , k in people :
14
+ ans .insert (k , (h , k ))
15
+ return ans
You can’t perform that action at this time.
0 commit comments