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
原题链接:220. 存在重复元素 III
解题思路:
i
j
true
false
/** * @param {number[]} nums * @param {number} k * @param {number} t * @return {boolean} */ var containsNearbyAlmostDuplicate = function(nums, k, t) { // 遍历下标i for (let i = 0; i < nums.length; i++) { // 遍历下标j,j为i之后的所有下标 for (let j = i + 1; j < nums.length; j++) { // 根据题意,查询是否存在满足条件的下标,有则返回true if (Math.abs(nums[i] - nums[j]) <= t && Math.abs(i - j) <= k) { return true; } } } // 如果正常退出循环,表示没有找到下标,返回false return false; };
The text was updated successfully, but these errors were encountered:
No branches or pull requests
原题链接:220. 存在重复元素 III
解题思路:
i
和j
,并根据要求判断下标是否满足条件,满足则返回true
。false
。j
只需要遍历i
之后的下标即可。The text was updated successfully, but these errors were encountered: