contains-duplicate.dart (519B)
1 //This is the intuitive solution that is too slow for leetcode. 2 //The time complexity of this code is O(n^2) where n is the length of the list "nums" 3 class Solution { 4 bool containsNearbyDuplicate(List<int> nums, int k) { 5 for(int i = 0 ; i < nums.length ; ++i){ 6 for(int x = i + 1; x < nums.length ; ++x){ 7 if(nums[i] == nums[x]){ 8 if((i - x).abs() <= k){ 9 return true; 10 } 11 } 12 } 13 } 14 return false; 15 } 16 }