随笔分类 - LetCode
LetCode 刷题
摘要: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. 第
阅读全文
摘要: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 -
阅读全文
摘要: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
阅读全文
摘要:给定一个整数数组 arr,如果它是有效的山脉数组就返回 true,否则返回 false 第一种方法:先求出最大数的下标,然后判断最大数左边和右边的元素都小于最大数 def validMountainArray(arr): index = arr.index(max(arr)) if index ==
阅读全文
摘要:给定一个数组 nums,编写一个函数将所有 0 移动到数组的末尾,同时保持非零元素的相对顺序。 第一种方法思路: 当列表中的元素是0时, 将0添加在元素末尾,然后删除对应的0 def moveZeroes(nums: List[int]) -> None: i = 0 count = 0 while
阅读全文
摘要:给定一个二进制数组, 计算其中最大连续 1 的个数 第一种方法: 将count存入一个ans的列表中,取得列表中最大值即为最大连续1的个数 def findMaxConsecutiveOnes(nums: List[int]) -> int: ans = [] count = 0 if 1 not
阅读全文

浙公网安备 33010602011771号