Skip to content

Commit 8fa53a7

Browse files
committed
2020-07-03
1 parent 6ebeecd commit 8fa53a7

File tree

3 files changed

+85
-0
lines changed

3 files changed

+85
-0
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Definition for singly-linked list.
2+
# class ListNode(object):
3+
# def __init__(self, val=0, next=None):
4+
# self.val = val
5+
# self.next = next
6+
class Solution(object):
7+
def deleteNodes(self, head, m, n):
8+
"""
9+
:type head: ListNode
10+
:type m: int
11+
:type n: int
12+
:rtype: ListNode
13+
"""
14+
if not head:
15+
return head
16+
17+
p = head
18+
tm = m - 1
19+
while tm and p:
20+
tm -= 1
21+
p = p.next
22+
if p:
23+
pp = p.next
24+
tn = n
25+
while tn and pp:
26+
tn -= 1
27+
pp = pp.next
28+
29+
p.next = self.deleteNodes(pp, m, n)
30+
return head
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
class Solution(object):
2+
def finalPrices(self, prices):
3+
"""
4+
:type prices: List[int]
5+
:rtype: List[int]
6+
"""
7+
stack = []
8+
res = []
9+
for i in range(len(prices) - 1, -1, -1):
10+
if not stack:
11+
res.append(prices[i])
12+
else:
13+
while stack and stack[-1] > prices[i]:
14+
stack.pop()
15+
if stack:
16+
res.append(prices[i] - stack[-1])
17+
else:
18+
res.append(prices[i])
19+
stack.append(prices[i])
20+
return res[::-1]
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
class SubrectangleQueries(object):
2+
3+
def __init__(self, rectangle):
4+
"""
5+
:type rectangle: List[List[int]]
6+
"""
7+
self.l = rectangle
8+
9+
def updateSubrectangle(self, row1, col1, row2, col2, newValue):
10+
"""
11+
:type row1: int
12+
:type col1: int
13+
:type row2: int
14+
:type col2: int
15+
:type newValue: int
16+
:rtype: None
17+
"""
18+
for i in range(row1, row2 + 1):
19+
for j in range(col1, col2 + 1):
20+
self.l[i][j] = newValue
21+
22+
23+
def getValue(self, row, col):
24+
"""
25+
:type row: int
26+
:type col: int
27+
:rtype: int
28+
"""
29+
return self.l[row][col]
30+
31+
32+
# Your SubrectangleQueries object will be instantiated and called as such:
33+
# obj = SubrectangleQueries(rectangle)
34+
# obj.updateSubrectangle(row1,col1,row2,col2,newValue)
35+
# param_2 = obj.getValue(row,col)

0 commit comments

Comments
 (0)