We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 5b5096e commit 39fdc72Copy full SHA for 39fdc72
Leetcode/LongestIncreasingFibonacciSubsequence.cpp
@@ -0,0 +1,40 @@
1
+class Solution {
2
+public:
3
+ int lenLongestFibSubseq(vector<int>& arr) {
4
+
5
+ unordered_set<int>s;
6
+ int n = arr.size();
7
8
+ for(int i=0;i<n;i++){
9
+ s.insert(arr[i]);
10
+ }
11
12
+ int ans = 0;
13
14
15
+ for(int j=i+1;j<n;j++){
16
+ int first = arr[i];
17
+ int second = arr[j];
18
+ int next = first + second;
19
20
+ int c = 2;
21
22
+ while(s.find(next)!=s.end()){
23
+ int temp = next;
24
+ next = next+second;
25
+ first = second;
26
+ second = temp;
27
+ c++;
28
29
30
+ ans = max(ans,c);
31
32
33
34
+ if(ans == 2)
35
+ return 0;
36
37
+ return ans;
38
39
40
+};
0 commit comments