Skip to content

Commit 5302471

Browse files
authored
Add files via upload
1 parent 1357b0d commit 5302471

File tree

3 files changed

+40
-0
lines changed

3 files changed

+40
-0
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# 每次取出最大的两个元素相减,结果不为0则添加到列表中
2+
class Solution(object):
3+
def lastStoneWeight(self, stones):
4+
while len(stones) > 1:
5+
y = stones.pop(stones.index(max(stones)))
6+
x = stones.pop(stones.index(max(stones)))
7+
if x < y:
8+
stones.append(y-x)
9+
return stones[0] if stones else 0

leetcode2/1109.航班预订统计.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# 前缀和解法,类似公交站记录上车人数和下车人数,每一站的人数为上一站的人数加上当前站的变化人数
2+
class Solution(object):
3+
def corpFlightBookings(self, bookings, n):
4+
res = [0]*n
5+
for b in bookings:
6+
l, r = b[0]-1, b[1]
7+
res[l] += b[2]
8+
if r < n:
9+
res[r] -= b[2]
10+
for i in range(1, n):
11+
res[i] += res[i-1]
12+
return res

leetcode2/1114.按序打印.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# 使用全局变量作为标记
2+
class Foo(object):
3+
def __init__(self):
4+
self.flag = 1
5+
6+
def first(self, printFirst):
7+
printFirst()
8+
self.flag = 2
9+
10+
def second(self, printSecond):
11+
while self.flag != 2:
12+
pass
13+
printSecond()
14+
self.flag = 3
15+
16+
def third(self, printThird):
17+
while self.flag != 3:
18+
pass
19+
printThird()

0 commit comments

Comments
 (0)