We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
给定一个无序的数组,找出数组在排序之后,相邻元素之间最大的差值。
如果数组元素个数小于 2,则返回 0。
示例1:
输入: [3,6,9,1] 输出: 3 解释: 排序后的数组是 [1,3,6,9], 其中相邻元素 (3,6) 和 (6,9) 之间都存在最大差值 3。
示例2:
输入: [10] 输出: 0 解释: 数组元素个数小于 2,因此返回 0。
说明:
The text was updated successfully, but these errors were encountered:
/** * @param {number[]} nums * @return {number} */ var maximumGap = function(nums) { const len = nums.length; if (len < 2) return 0; nums.sort((a, b) => a - b); let max = -1; for (let i = 1; i < len; i++) { const val = nums[i] - nums[i - 1]; if (val > max) { max = val } } return max; };
Sorry, something went wrong.
No branches or pull requests
164. 最大间距
给定一个无序的数组,找出数组在排序之后,相邻元素之间最大的差值。
如果数组元素个数小于 2,则返回 0。
示例1:
示例2:
说明:
The text was updated successfully, but these errors were encountered: