Longest Ascending SubArray (continuous)

class Solution { public: int longest(vector<int>& array) { if (array.empty()) return 0; vector<int> memo; memo.push_back(1); int global_max = 1; for (int i = 1; i < array.size(); i++){ if (array[i] > array[i-1]) memo.push_back(memo[i-1] + 1); else memo.push_back(1); global_max = memo[i] > global_max? memo[i] : global_max; } return global_max; } };
LaiCode version, must be continuous. Use DP

Mistakes:
- Missed out corner case: array is empty. Should return 0;
- Else, global_max should start from 1, not zero. The minimum is zero!

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.