File tree Expand file tree Collapse file tree 4 files changed +80
-0
lines changed
300.Longest-Increasing-Subsequence
674.Longest-Continuous-Increasing-Subsequence Expand file tree Collapse file tree 4 files changed +80
-0
lines changed Original file line number Diff line number Diff line change
1
+ class Solution {
2
+ public:
3
+ int lengthOfLIS (vector<int >& nums) {
4
+ int maxlen = 0 ;
5
+
6
+ vector<int > dp (nums.size ());
7
+ for (int i=0 ;i<nums.size ();i++){
8
+ int max_dp = 0 ;
9
+ for (int j=0 ;j<i;j++){
10
+ if (nums[i] > nums[j])
11
+ max_dp = max (dp[j], max_dp);
12
+ }
13
+ dp[i] = max_dp + 1 ;
14
+ maxlen = max (dp[i], maxlen);
15
+ }
16
+ return maxlen;
17
+ }
18
+ };
Original file line number Diff line number Diff line change
1
+ class Solution {
2
+ public:
3
+ int findLengthOfLCIS (vector<int >& nums) {
4
+ if (nums.size () == 0 )
5
+ return 0 ;
6
+
7
+ int max = 1 ;
8
+ int temp = 1 ;
9
+ int last = nums[0 ];
10
+ for (int i=1 ;i<nums.size ();i++){
11
+ if (nums[i] > last){
12
+ temp += 1 ;
13
+ if (temp > max)
14
+ max = temp;
15
+ }
16
+ else {
17
+ temp = 1 ;
18
+ }
19
+ last = nums[i];
20
+ }
21
+ return max;
22
+ }
23
+ };
Original file line number Diff line number Diff line change
1
+ class Solution {
2
+ public:
3
+ bool validPalindrome (string s) {
4
+ bool skipFlag = true ;
5
+ bool result = true ;
6
+ for (int cur1=0 , cur2=s.size ()-1 ; cur1 < cur2; cur1++,cur2--){
7
+ if (s[cur1] != s[cur2]){
8
+ if (skipFlag && s[cur1+1 ] == s[cur2]){
9
+ cur1 ++;
10
+ skipFlag = false ;
11
+ }
12
+ else {
13
+ result = false ;
14
+ break ;
15
+ }
16
+ }
17
+ }
18
+ if (result)
19
+ return result;
20
+
21
+ skipFlag = true ;
22
+ result = true ;
23
+ for (int cur1=0 , cur2=s.size ()-1 ; cur1 < cur2; cur1++,cur2--){
24
+ if (s[cur1] != s[cur2]){
25
+ if (skipFlag && s[cur1] == s[cur2-1 ]){
26
+ cur2 --;
27
+ skipFlag = false ;
28
+ }
29
+ else {
30
+ result = false ;
31
+ break ;
32
+ }
33
+ }
34
+ }
35
+ return result;
36
+ }
37
+ };
Original file line number Diff line number Diff line change 437
437
438
438
[ 299.Bulls-and-Cows] ( Algorithms/299.Bulls-and-Cows/solution.cpp )
439
439
440
+ [ 300.Longest-Increasing-Subsequence] ( Algorithms/300.Longest-Increasing-Subsequence/solution.cpp )
441
+
440
442
[ 303.Range-Sum-Query---Immutable] ( Algorithms/303.Range-Sum-Query---Immutable/solution.cpp )
441
443
442
444
[ 309.Best-Time-to-Buy-and-Sell-Stock-with-Cooldown] ( Algorithms/309.Best-Time-to-Buy-and-Sell-Stock-with-Cooldown/solution.cpp )
You can’t perform that action at this time.
0 commit comments