Logo
IconChallenge
Icon
IconProblem
IconSolutions
IconSubmissions

Additive Number

XPChallenge Points: 20
levelLevel: Medium

You are given a string num consisting only of digits.
Your task is to determine whether the digits can form a valid additive sequence.
An additive sequence is a sequence of numbers where each number is the sum of the previous two, and the sequence contains at least three numbers.
• Numbers in the sequence cannot have leading zeros (e.g., 1, 2, 03 is invalid).
• The sequence must use all digits of the string.
Return true if the number string can form such a sequence, otherwise return false.

Example 1:

Input: num = "23581321"

Output: true

Example 2:

Input: num = "112359"

Output: false

to Continue
like
dislike

Accepted:

Submission:

IconReport an issue
Icon
IconCode
IconYou need toto run or submitYou need toto run or submit
IconTest Case
IconTest Result