一、英语
1、mortifying:令人羞愧的、令人窘迫的
2、detect with a critical eye:用吹毛求疵的眼光去看待
3、attend to:关心、关注
二、算法题目
1、769:数组index的巧妙应用
class Solution:
def maxChunksToSorted(self, arr: List[int]) -> int:
#倒序的数字必须在一个块中进行排序,否则连接之后也是无序的
#这里数字是从1到n-1,这时候数组的index是可以利用的信息
#记录当前的最大值,如果最最大值大于index,那么说明index右边还有比max小的数,那么要继续扩大块范围
#如果max==index,那么说明考虑了所有的逆序,最大的为max,进行一次分块
n = len(arr)
res = 0
max_n = 0
for i in range(n):
max_n = max(max_n,arr[i])
if max_n == i:
res += 1
#这里后面的分段一定比已经分段的数字大
#所以max_n这里可以不用初始化为0
#max_n = 0
return res
2、232:数据结构:栈和队列
class MyQueue:
#两个list
#push:直接加入到list1中
#pop:将list1中的元素从尾道头赋值给list2,并将list1清空,pop返回的是list2的尾部元素
#peek:如果list2不为空,那么fron就是list2尾部元素,如果list2为空,那么就是list1的第一个元素
#empty:list1和list2都为空
def __init__(self):
"""
Initialize your data structure here.
"""
self.list1 = []
self.list2 = []
def push(self, x: int) -> None:
"""
Push element x to the back of queue.
"""
self.list1.append(x)
def pop(self) -> int:
"""
Removes the element from in front of queue and returns that element.
"""
#用完之后再向list2中加入数字,这样可以保证顺序的正确,而不是list1接收一个就加入一个
if self.list2 == []:
for i in self.list1[::-1]:
self.list2.append(i)
self.list1.clear()
return self.list2.pop()
def peek(self) -> int:
"""
Get the front element.
"""
if self.list2:
return self.list2[-1]
else:
return self.list1[0]
def empty(self) -> bool:
"""
Returns whether the queue is empty.
"""
return self.list1==[] and self.list2==[]
# Your MyQueue object will be instantiated and called as such:
# obj = MyQueue()
# obj.push(x)
# param_2 = obj.pop()
# param_3 = obj.peek()
# param_4 = obj.empty()
生活得向前看