-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathfibo.py
More file actions
58 lines (48 loc) · 1.1 KB
/
fibo.py
File metadata and controls
58 lines (48 loc) · 1.1 KB
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
48
49
50
51
52
53
54
55
56
57
def solution(K, A):
# write your code in Python 3.6
"""
n = len(A)
count = 0
match = []
for i in range(n):
if K - A[i] in A[i:]:
match.append((i,A.index(K-A[i])))
count += 1
if i != A.index(K-A[i]):
count += 1
#print(match)
return count"""
n = len(A)
count = 0
for i in range(n):
for j in range(i,n):
if A[i] + A[j] == K:
count += 1
if i != j:
count += 1
return count
"""
n = len(A)
count = 0
for i in range(n):
#print(i)
for j in range(n):
if A[i] + A[j] == K:
#print(i,j)
count += 1
return count
"""
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
fibo = [0,1]
def solution(N):
if N == 0:
return 0
elif N == 1:
return 1
elif len(fibo)>N:
return fibo[N]
else:
value = solution(N-1) + solution(N-2)
fibo.append(value)
return value%1000000