diff --git a/LeetCode Solutions/Longest Increasing Subsequence.cpp b/LeetCode Solutions/Longest Increasing Subsequence.cpp new file mode 100644 index 0000000..0bb7e64 --- /dev/null +++ b/LeetCode Solutions/Longest Increasing Subsequence.cpp @@ -0,0 +1,19 @@ +class Solution { +public: + int lengthOfLIS(vector& nums) { + int n = nums.size(); + + vectorLIS(n+1, 1); + + for (int i = 0; i < n; i++) + for (int j = 0; j < i; j++) + if (nums[i] > nums[j]) + LIS[i] = max(LIS[i], 1 + LIS[j]); + + int ans = 0; //return max of whole array + for (int i = 0; i < n; i++) + ans = max(ans, LIS[i]); + + return ans; + } +};