leetcode

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README

commit b770abb6819ed065b0bd719448bd8d2eb24dd980
parent e58286d7a6e800ab3a8e535874a79b32243bc9f6
Author: AndrewLockVI <andrewlaack1@gmail.com>
Date:   Sat,  6 May 2023 08:52:14 -0500

Completed contains duplicate ii with dart

Diffstat:
Acontains-duplicate-ii/contains-duplicate.dart | 16++++++++++++++++
1 file changed, 16 insertions(+), 0 deletions(-)

diff --git a/contains-duplicate-ii/contains-duplicate.dart b/contains-duplicate-ii/contains-duplicate.dart @@ -0,0 +1,16 @@ +//This is the intuitive solution that is too slow for leetcode. +//The time complexity of this code is O(n^2) where n is the length of the list "nums" +class Solution { + bool containsNearbyDuplicate(List<int> nums, int k) { + for(int i = 0 ; i < nums.length ; ++i){ + for(int x = i + 1; x < nums.length ; ++x){ + if(nums[i] == nums[x]){ + if((i - x).abs() <= k){ + return true; + } + } + } + } + return false; + } +}