File tree Expand file tree Collapse file tree 1 file changed +21
-1
lines changed Expand file tree Collapse file tree 1 file changed +21
-1
lines changed Original file line number Diff line number Diff line change @@ -51,7 +51,7 @@ https://leetcode-cn.com/problems/contains-duplicate-ii/
5151
5252## 代码
5353
54- * 语言支持:JS,Python,C++
54+ * 语言支持:JS,Python,C++, Java
5555
5656Javascript Code:
5757
@@ -86,6 +86,7 @@ class Solution:
8686 d[num] = index
8787 return False
8888```
89+
8990C++ Code:
9091``` C++
9192class Solution {
@@ -106,6 +107,25 @@ public:
106107};
107108```
108109
110+ Java Code:
111+
112+ ```java
113+ class Solution {
114+ public boolean containsNearbyDuplicate(int[] nums, int k) {
115+ Map<Integer, Integer> map = new HashMap<>();
116+ for(int i=0;i<nums.length;i++)
117+ {
118+ if(map.get(nums[i]) != null && (i-map.get(nums[i])) <= k)
119+ {
120+ return true;
121+ }
122+ map.put(nums[i], i);
123+ }
124+ return false;
125+ }
126+ }
127+ ```
128+
109129** 复杂度分析**
110130- 时间复杂度:$O(N)$
111131- 空间复杂度:$O(N)$
You can’t perform that action at this time.
0 commit comments