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

Commit546f6c1

Browse files
authored
Implement totalWaviness method in Solution class
1 parent6437057 commit546f6c1

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
classSolution {
2+
publicinttotalWaviness(intnum1,intnum2) {
3+
intcount =0;
4+
for (inti =num1;i <=num2;i++) {
5+
count +=calculateWaviness(i);
6+
}
7+
returncount;
8+
}
9+
10+
privatestaticintcalculateWaviness(intnum) {
11+
Strings =String.valueOf(num);
12+
intn =s.length();
13+
if (n <3) {
14+
return0;
15+
}
16+
intcount =0;
17+
for (inti =1;i <n -1;i++) {
18+
if (s.charAt(i) >s.charAt(i -1) &&s.charAt(i) >s.charAt(i +1)) {
19+
count++;
20+
}
21+
if (s.charAt(i) <s.charAt(i -1) &&s.charAt(i) <s.charAt(i +1)) {
22+
count++;
23+
}
24+
}
25+
returncount;
26+
}
27+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp