Skip to content

Commit 7c9cbf0

Browse files
refactor 306
1 parent ffd5988 commit 7c9cbf0

File tree

1 file changed

+3
-22
lines changed
  • src/main/java/com/fishercoder/solutions

1 file changed

+3
-22
lines changed

src/main/java/com/fishercoder/solutions/_306.java

Lines changed: 3 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,10 @@
11
package com.fishercoder.solutions;
22

3-
/**
4-
* 306. Additive Number
5-
*
6-
* Additive number is a string whose digits can form additive sequence.
7-
8-
A valid additive sequence should contain at least three numbers.
9-
Except for the first two numbers, each subsequent number in the sequence must be the sum of the preceding two.
10-
11-
For example:
12-
"112358" is an additive number because the digits can form an additive sequence: 1, 1, 2, 3, 5, 8.
13-
14-
1 + 1 = 2, 1 + 2 = 3, 2 + 3 = 5, 3 + 5 = 8
15-
"199100199" is also an additive number, the additive sequence is: 1, 99, 100, 199.
16-
1 + 99 = 100, 99 + 100 = 199
17-
Note: Numbers in the additive sequence cannot have leading zeros, so sequence 1, 2, 03 or 1, 02, 3 is invalid.
18-
19-
Given a string containing only digits '0'-'9', write a function to determine if it's an additive number.
20-
21-
Follow up:
22-
How would you handle overflow for very large input integers?
23-
*/
243
public class _306 {
254
public static class Solution1 {
26-
/** Credit: https://discuss.leetcode.com/topic/29856/java-recursive-and-iterative-solutions/2 */
5+
/**
6+
* Credit: https://discuss.leetcode.com/topic/29856/java-recursive-and-iterative-solutions/2
7+
*/
278
public boolean isAdditiveNumber(String num) {
289
int n = num.length();
2910
for (int i = 1; i <= n / 2; ++i) {

0 commit comments

Comments
 (0)