Skip to content

Latest commit

 

History

History
22 lines (19 loc) · 676 Bytes

Question_2903.md

File metadata and controls

22 lines (19 loc) · 676 Bytes

LeetCode Records - Question 2903 Find Indices With Index and Value Difference I

Attempt 1: Use a nested loop to test every case

class Solution {
    public int[] findIndices(int[] nums, int indexDifference, int valueDifference) {
        for (int i = 0; i < nums.length - indexDifference; i++) {
            for (int j = i + indexDifference; j < nums.length; j++) {
                if (Math.abs(nums[i] - nums[j]) >= valueDifference) {
                    return new int[]{i, j};
                }
            }
        }

        return new int[]{-1, -1};
    }
}
  • Runtime: 1 ms (Beats: 98.88%)
  • Memory: 43.55 MB (Beats: 19.33%)