博主提交的代码 classSolution{publicdoubletrimMean(int[]arr){intoffSet=(int)(arr.length*0.05);doubleresult=0;Arrays.sort(arr);for(inti=offSet;i<arr.length-offSet;i++){result+=arr[i];}returnresult/(arr.length-offSet*2);}} 其他人优秀的代码 https://leetcode.com/problems/mean-of-array-aft...
https://leetcode.com/problems/number-of-good-pairs/ Given an array of integers nums. A pair (i,j) is called good if nums[i] == nums[j] and i < j. Return the number of good pairs. Example 1: Input: nums = [1,2,3,1,1,3] Output: 4 Explanation: There are 4 good pairs (...
It doesn't matter what you leave beyond the new length. 题目地址:https://leetcode.com/problems/remove-duplicates-from-sorted-array/description/ 题意:给定一个已经排序好的数组,用O(1)的空间在原数组去掉重复的数,返回新的长度 思路:利用双指针,一个指向当前不重复的长度len,一个指向遍历看不重复的写...
https://leetcode.com/problems/find-all-numbers-disappeared-in-an-array/description/ 题目描述: Given an array of integers where 1 ≤ a[i] ≤n(n= size of array), some elements appear twice and others appear once. Find all the elements of [1,n] inclusive that do not appear in this ar...
关键词 字符串 题目描述 https://leetcode.com/problems/find-words-that-can-be-formed-by-characters/...
截止至今LeetCode题目总量已经有1582题,估计将来每年平均增长300题左右,大部分人肯定是刷不完的,所以得有选择地刷LeetCode。
题目地址:https://leetcode-cn.com/problems/non-decreasing-array/ 题目描述 给你一个长度为 n 的整数数组,请你判断在 最多 改变 1 个元素的情况下,该数组能否变成一个非递减数列。 我们是这样定义一个非递减数列的: 对于数组中所有的i (0 <= i <= n-2),总满足nums[i] <= nums[i + 1]。
截止至今LeetCode题目总量已经有1582题,估计将来每年平均增长300题左右,大部分人肯定是刷不完的,所以得有选择地刷LeetCode。 一种公认的刷题策略是按类别刷题,可是每个类别也有许多题,在有限的时间里到底该刷哪些题呢?个人根据LeetCode官方给出的每个题目的出现频率,整理并收录了每个类别里高频出现的题目,对于官方统...
日期 题目地址:https://leetcode.com/problems/contiguous-array/description/ 题目描述 Given a binary array, find the maximum length of a contiguous subarray with equal number of 0 and 1. Example 1: Input: [0,1] ...