File tree 1 file changed +11
-18
lines changed
scripts/algorithms/C/Contains Duplicate III
1 file changed +11
-18
lines changed Original file line number Diff line number Diff line change
1
+ // Runtime: 4931 ms (Top 33.3%) | Memory: 51.20 MB (Top 40.3%)
2
+
1
3
/**
2
4
* @param {number[] } nums
3
5
* @param {number } k
4
6
* @param {number } t
5
7
* @return {boolean }
6
8
*/
7
9
var containsNearbyAlmostDuplicate = function ( nums , k , t ) {
8
- if ( nums . length < 2 ) return false ;
9
-
10
- let isValid = false ;
11
-
12
- for ( var indexI = 0 ; indexI < nums . length ; indexI ++ ) {
13
- let indexJ = indexI + 1 ;
14
- while ( ( indexJ - indexI ) <= k ) {
15
- if ( Math . abs ( nums [ indexI ] - nums [ indexJ ] ) <= t ) {
16
- isValid = true ;
17
- break ;
18
- }
19
- indexJ ++ ;
20
- }
21
- if ( isValid ) break ;
22
- }
23
-
24
- return isValid ;
25
- } ;
10
+ for ( let i = 0 ; i < nums . length ; i ++ ) {
11
+ for ( let j = i + 1 ; j < nums . length ; j ++ ) {
12
+ if ( Math . abs ( nums [ i ] - nums [ j ] ) <= t && ( Math . abs ( i - j ) <= k ) ) {
13
+ return true ;
14
+ }
15
+ }
16
+ }
17
+ return false ;
18
+ } ;
You can’t perform that action at this time.
0 commit comments