<p>An <strong>additive number</strong> is a string whose digits can form an <strong>additive sequence</strong>.</p>

<p>A valid <strong>additive sequence</strong> should contain <strong>at least</strong> three numbers. Except for the first two numbers, each subsequent number in the sequence must be the sum of the preceding two.</p>

<p>Given a string containing only digits, return <code>true</code> if it is an <strong>additive number</strong> or <code>false</code> otherwise.</p>

<p><strong>Note:</strong> Numbers in the additive sequence <strong>cannot</strong> have leading zeros, so sequence <code>1, 2, 03</code> or <code>1, 02, 3</code> is invalid.</p>

<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>

<pre>
<strong>Input:</strong> &quot;112358&quot;
<strong>Output:</strong> true
<strong>Explanation:</strong> 
The digits can form an additive sequence: 1, 1, 2, 3, 5, 8. 
1 + 1 = 2, 1 + 2 = 3, 2 + 3 = 5, 3 + 5 = 8
</pre>

<p><strong class="example">Example 2:</strong></p>

<pre>
<strong>Input:</strong> &quot;199100199&quot;
<strong>Output:</strong> true
<strong>Explanation:</strong> 
The additive sequence is: 1, 99, 100, 199.&nbsp;
1 + 99 = 100, 99 + 100 = 199
</pre>

<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>

<ul>
	<li><code>1 &lt;= num.length &lt;= 35</code></li>
	<li><code>num</code> consists only of digits.</li>
</ul>

<p>&nbsp;</p>
<p><strong>Follow up:</strong> How would you handle overflow for very large input integers?</p>

class Solution {
public:
    bool isAdditive(string n1, string n2, string curr, int isTrue) {
        if(curr.size()==0 && isTrue ==true)
        return true;
        // if(curr.size()==0 && isTrue ==false)
        // return false;
        long long s1 = stol(n1);
        long long s2 = stol(n2);
        long long num3 = s1+s2;
        string n3 = to_string(num3);
        if(curr.substr(0, n3.length())== n3) {
            return isAdditive(n2, n3, curr.substr(n3.length()), true);
        }
        return false;
    }
    bool isAdditiveNumber(string s) {
        if(s.length()<=2) return false;
        string s1="", s2 = "";
        for(int i=1;i<s.length()-1;i++) {
            s1 = s.substr(0, i);
            long long st = stol(s1);
            if(to_string(st)!= s1) return false;
            for(int j = i;j<s.size();j++) {
                s2 = s.substr(i, j-i+1);
                long long st2 = stol(s2);
               
                int f = isAdditive(s1, s2, s.substr(j+1), false);
                 
                if(f ==true && s2==to_string(st2))
                return true;
            }
        }
        return false;
    }
};
9800