219. Contains Duplicate II Easy

@problem@discussion
#Array#Hash Table#Sliding Window



1/**
2 * [219] Contains Duplicate II
3 *
4 * Given an integer array nums and an integer k, return true if there are two distinct indices i and j in the array such that nums[i] == nums[j] and abs(i - j) <= k.
5 *  
6 * Example 1:
7 * 
8 * Input: nums = [1,2,3,1], k = 3
9 * Output: true
10 * 
11 * Example 2:
12 * 
13 * Input: nums = [1,0,1,1], k = 1
14 * Output: true
15 * 
16 * Example 3:
17 * 
18 * Input: nums = [1,2,3,1,2,3], k = 2
19 * Output: false
20 * 
21 *  
22 * Constraints:
23 * 
24 * 	1 <= nums.length <= 10^5
25 * 	-10^9 <= nums[i] <= 10^9
26 * 	0 <= k <= 10^5
27 * 
28 */
29pub struct Solution {}
30
31// problem: https://leetcode.com/problems/contains-duplicate-ii/
32// discuss: https://leetcode.com/problems/contains-duplicate-ii/discuss/?currentPage=1&orderBy=most_votes&query=
33
34// submission codes start here
35
36impl Solution {
37    pub fn contains_nearby_duplicate(nums: Vec<i32>, k: i32) -> bool {
38        false
39    }
40}
41
42// submission codes end
43
44#[cfg(test)]
45mod tests {
46    use super::*;
47
48    #[test]
49    fn test_219() {
50    }
51}
52


Back
© 2025 bowen.ge All Rights Reserved.