-
Notifications
You must be signed in to change notification settings - Fork 0
/
486. 预测赢家.py
43 lines (38 loc) · 1011 Bytes
/
486. 预测赢家.py
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
#!/usr/bin/env python
# _*_coding:utf-8 _*_
"""
@Time :2020/9/1 12:02 上午
@Author :[email protected]
@File :486. 预测赢家.py
@Description :
"""
class Solution(object):
def PredictTheWinner(self, nums):
"""
:type nums: List[int]
:rtype: bool
"""
one = []
two = []
while len(nums) > 0:
if nums[0] > nums[-1]:
one.append(nums[0])
nums.pop(0)
else:
one.append(nums[-1])
nums.pop(-1)
if len(nums) > 0:
if nums[0] > nums[-1]:
two.append(nums[0])
nums.pop(0)
else:
two.append(nums[-1])
nums.pop(-1)
oneres = sum(one)
twores = sum(two)
if oneres > twores:
return True
else:
return False
if __name__ == '__main__':
print Solution().PredictTheWinner([1, 5, 233, 7])