-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtapeequilibrium.py
More file actions
59 lines (37 loc) · 825 Bytes
/
tapeequilibrium.py
File metadata and controls
59 lines (37 loc) · 825 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
48
49
50
51
52
53
54
55
56
57
58
59
# -*- coding: utf-8 -*-
"""
Created on Thu Nov 11 16:36:42 2021
@author: user
"""
#코딜리티
#lesson 3
#tapeequilibrium
A = [3,1,2,4,3]
#%%
### 첫번째 시도 -53%(전부 시간 초과)
def solution(A):
diff = []
for p in range(1, len(A)) :
tape1 = A[:p]
tape2 = A[p:len(A)]
print(tape1)
print(tape2)
sum1 = sum(tape1)
sum2 = sum(tape2)
print(sum1)
print(sum2)
diff.append(abs(sum1 - sum2))
print(diff)
diff = min(diff)
return diff
#%%
### 두번째 시도 - 100%
def solution(A) :
tape1 = 0
tape2 = sum(A)
diff = []
for p in A :
tape1 += p
tape2 -= p
diff.append(abs(tape1 - tape2))
return min(diff[:-1])