12 2021 档案

摘要:Given an integer array nums, return the third distinct maximum number in this array. If the third maximum does not exist, return the maximum number. 第 阅读全文
posted @ 2021-12-29 21:08 焰红火 阅读(35) 评论(0) 推荐(0)
摘要:def func(): try: x = 1 y = 0 assert x + y == 0, 'x +y != 0, x + y is {}'.format(x + y) except AssertionError as err: # raise AssertionError('abc ') # 阅读全文
posted @ 2021-12-28 23:08 焰红火 阅读(111) 评论(0) 推荐(0)
摘要:Given an array arr, replace every element in that array with the greatest element among the elements to its right, and replace the last element with - 阅读全文
posted @ 2021-12-28 21:03 焰红火 阅读(60) 评论(0) 推荐(0)
摘要:A school is trying to take an annual photo of all the students. The students are asked to stand in a single file line in non-decreasing order by heigh 阅读全文
posted @ 2021-12-28 20:12 焰红火 阅读(67) 评论(0) 推荐(0)
摘要:给定一个整数数组 arr,如果它是有效的山脉数组就返回 true,否则返回 false 第一种方法:先求出最大数的下标,然后判断最大数左边和右边的元素都小于最大数 def validMountainArray(arr): index = arr.index(max(arr)) if index == 阅读全文
posted @ 2021-12-27 17:13 焰红火 阅读(55) 评论(0) 推荐(0)
摘要:给定一个数组 nums,编写一个函数将所有 0 移动到数组的末尾,同时保持非零元素的相对顺序。 第一种方法思路: 当列表中的元素是0时, 将0添加在元素末尾,然后删除对应的0 def moveZeroes(nums: List[int]) -> None: i = 0 count = 0 while 阅读全文
posted @ 2021-12-26 17:13 焰红火 阅读(42) 评论(0) 推荐(0)
摘要:给定一个二进制数组, 计算其中最大连续 1 的个数 第一种方法: 将count存入一个ans的列表中,取得列表中最大值即为最大连续1的个数 def findMaxConsecutiveOnes(nums: List[int]) -> int: ans = [] count = 0 if 1 not 阅读全文
posted @ 2021-12-25 20:52 焰红火 阅读(100) 评论(0) 推荐(0)
摘要:迭代相关的概念 可迭代对象: 如果对象是实际保存的序列或者可以在迭代工具上下文中一次只生成一个结果的对象, 那么就可以看做是可迭代的 完整的迭代协议: 可迭代对象: 迭代的被调对象,其 __iter__方法被iter函数所调用 迭代器对象: 可迭代对象返回的结果在迭代过程中实际提供对象的值, 它的_ 阅读全文
posted @ 2021-12-24 17:14 焰红火 阅读(88) 评论(0) 推荐(0)