Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commita89344a

Browse files
committed
Added Longest Arithmetic Subsequence of Given Difference.java
1 parent3523744 commita89344a

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
classSolution {
2+
publicintlongestSubsequence(int[]arr,intdifference) {
3+
Map<Integer,Integer>map =newHashMap<>();
4+
intmaxValue =0;
5+
for (intnum :arr) {
6+
intendingSubLength =map.getOrDefault(num -difference,0);
7+
map.put(num,endingSubLength +1);
8+
maxValue =Math.max(maxValue,map.get(num));
9+
}
10+
returnmaxValue;
11+
}
12+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp