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

Commitd5d67b5

Browse files
authored
Merge pull requestneetcode-gh#3290 from a1exanddrovich/1849-dev
Create: 1849-splitting-a-string-into-descending-consecutive-values.java
2 parentsc142b02 +d841e41 commitd5d67b5

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
importjava.math.BigInteger;
2+
3+
classSolution {
4+
publicbooleansplitString(Strings) {
5+
for (inti =0;i <s.length() -1;i++) {
6+
BigIntegercurValue =newBigInteger(s.substring(0,i +1));
7+
if (backtrack(i +1,s,curValue)) {
8+
returntrue;
9+
}
10+
}
11+
12+
returnfalse;
13+
}
14+
15+
privatebooleanbacktrack(intstartIndex,
16+
Strings,
17+
BigIntegerlastValue) {
18+
if (startIndex >=s.length()) {
19+
returntrue;
20+
}
21+
22+
for (inti =startIndex;i <s.length();i++) {
23+
BigIntegercurValue =newBigInteger(s.substring(startIndex,i +1));
24+
if (lastValue.subtract(curValue).compareTo(BigInteger.ONE) ==0 &&
25+
backtrack(i +1,s,curValue)) {
26+
returntrue;
27+
}
28+
}
29+
30+
returnfalse;
31+
}
32+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp