-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathDictCode.py
More file actions
47 lines (37 loc) · 925 Bytes
/
Copy pathDictCode.py
File metadata and controls
47 lines (37 loc) · 925 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
from collections import defaultdict
def prepareDict(pairs):
map1 = defaultdict(list)
map2 = defaultdict(int)
for x in pairs:
parent = x[0]
child = x[1]
map1[parent].append(child)
map2[parent] += 1
print(map1)
print(map2)
pairs = [[1, 2], [1, 3], [1, 4], [2, 3], [2, 4]]
prepareDict(pairs)
# The guess API is already defined for you.
# @param num, your guess
# @return -1 if my number is lower, 1 if my number is higher, otherwise return 0
# def guess(num):
#
# class Solution(object):
# def guessNumber(self, n):
#
# low,high = 1, n
# while (low < high):
# mid = (low + high) >> 1
# if (guess(mid) == 0):
# return mid
# elif guess(mid) == -1:
# low = mid + 1
# else:
# high = mid - 1
#
#
#
# """
# :type n: int
# :rtype: int
# """