Class Solution
java.lang.Object
g0801_0900.s0842_split_array_into_fibonacci_sequence.Solution
842 - Split Array into Fibonacci Sequence.<p>Medium</p>
<p>You are given a string of digits <code>num</code>, such as <code>"123456579"</code>. We can split it into a Fibonacci-like sequence <code>[123, 456, 579]</code>.</p>
<p>Formally, a <strong>Fibonacci-like</strong> sequence is a list <code>f</code> of non-negative integers such that:</p>
<ul>
<li><code>0 <= f[i] < 2<sup>31</sup></code>, (that is, each integer fits in a <strong>32-bit</strong> signed integer type),</li>
<li><code>f.length >= 3</code>, and</li>
<li><code>f[i] + f[i + 1] == f[i + 2]</code> for all <code>0 <= i < f.length - 2</code>.</li>
</ul>
<p>Note that when splitting the string into pieces, each piece must not have extra leading zeroes, except if the piece is the number <code>0</code> itself.</p>
<p>Return any Fibonacci-like sequence split from <code>num</code>, or return <code>[]</code> if it cannot be done.</p>
<p><strong>Example 1:</strong></p>
<p><strong>Input:</strong> num = “1101111”</p>
<p><strong>Output:</strong> [11,0,11,11]</p>
<p><strong>Explanation:</strong> The output [110, 1, 111] would also be accepted.</p>
<p><strong>Example 2:</strong></p>
<p><strong>Input:</strong> num = “112358130”</p>
<p><strong>Output:</strong> []</p>
<p><strong>Explanation:</strong> The task is impossible.</p>
<p><strong>Example 3:</strong></p>
<p><strong>Input:</strong> num = “0123”</p>
<p><strong>Output:</strong> []</p>
<p><strong>Explanation:</strong> Leading zeroes are not allowed, so “01”, “2”, “3” is not valid.</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>1 <= num.length <= 200</code></li>
<li><code>num</code> contains only digits.</li>
</ul>
-
Constructor Summary
Constructors -
Method Summary
-
Constructor Details
-
Solution
public Solution()
-
-
Method Details
-
splitIntoFibonacci
-