"Contains Duplicate III" medium task No 220 accepted solution
This commit is contained in:
22
220-contains-duplicate-3.go
Normal file
22
220-contains-duplicate-3.go
Normal file
@@ -0,0 +1,22 @@
|
||||
package main
|
||||
|
||||
import "math"
|
||||
|
||||
func ContainsNearbyAlmostDuplicate(nums []int, k int, t int) bool {
|
||||
if k < 1 {
|
||||
return false
|
||||
}
|
||||
|
||||
for wSz := 1; wSz <= k; wSz++ {
|
||||
ws := 0
|
||||
for we := ws + wSz; we < len(nums); we++ {
|
||||
if int(math.Abs(float64(nums[ws]-nums[we]))) <= t {
|
||||
return true
|
||||
}
|
||||
ws++
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
Reference in New Issue
Block a user