본문 바로가기
python-algorithm

leetcode 2903. Find Indices With Index and Value Difference I

by 무적김두칠 2023. 12. 28.

https://leetcode.com/problems/find-indices-with-index-and-value-difference-i/description/

 

Find Indices With Index and Value Difference I - LeetCode

Can you solve this real interview question? Find Indices With Index and Value Difference I - You are given a 0-indexed integer array nums having length n, an integer indexDifference, and an integer valueDifference. Your task is to find two indices i and j,

leetcode.com

 

1
2
3
4
5
6
7
8
class Solution:
    def findIndices(self, nums: List[int], indexDifference: int, valueDifference: int-> List[int]:
        for i in range(len(nums)):
            for j in range(i+indexDifference, len(nums)):
                if abs(nums[i] - nums[j]) >= valueDifference:
                    return [i, j]
        
        return [-1,-1]
cs
반응형

댓글