You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: solution/1400-1499/1438.Longest Continuous Subarray With Absolute Diff Less Than or Equal to Limit/README.md
Copy file name to clipboardexpand all lines: solution/1400-1499/1438.Longest Continuous Subarray With Absolute Diff Less Than or Equal to Limit/README_EN.md
Copy file name to clipboardexpand all lines: solution/1400-1499/1438.Longest Continuous Subarray With Absolute Diff Less Than or Equal to Limit/Solution.go
Copy file name to clipboardexpand all lines: solution/1400-1499/1438.Longest Continuous Subarray With Absolute Diff Less Than or Equal to Limit/Solution.java
+5-7
Original file line number
Diff line number
Diff line change
@@ -1,15 +1,13 @@
1
1
classSolution {
2
2
publicintlongestSubarray(int[] nums, intlimit) {
3
3
TreeMap<Integer, Integer> tm = newTreeMap<>();
4
-
intans = 0, j = 0;
5
-
for (inti = 0; i < nums.length; ++i) {
6
-
tm.put(nums[i], tm.getOrDefault(nums[i], 0) + 1);
7
-
while (tm.lastKey() - tm.firstKey() > limit) {
8
-
tm.put(nums[j], tm.get(nums[j]) - 1);
9
-
if (tm.get(nums[j]) == 0) {
4
+
intans = 0;
5
+
for (inti = 0, j = 0; i < nums.length; ++i) {
6
+
tm.merge(nums[i], 1, Integer::sum);
7
+
for (; tm.lastKey() - tm.firstKey() > limit; ++j) {
Copy file name to clipboardexpand all lines: solution/1400-1499/1438.Longest Continuous Subarray With Absolute Diff Less Than or Equal to Limit/Solution.py
Copy file name to clipboardexpand all lines: solution/1400-1499/1438.Longest Continuous Subarray With Absolute Diff Less Than or Equal to Limit/Solution.ts
+1-1
Original file line number
Diff line number
Diff line change
@@ -4,7 +4,7 @@ function longestSubarray(nums: number[], limit: number): number {
0 commit comments