-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #595 from Shubh-Krishna/main
Day 15 q3 & Day 22 q2 & Day 18 Q2 & Day 17 q1 & Day 26 q2 Completed
- Loading branch information
Showing
5 changed files
with
85 additions
and
0 deletions.
There are no files selected for viewing
15 changes: 15 additions & 0 deletions
15
Day-15/q3-Longest Increasing Subsequence/Shubh_Krishna_solution.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
int lengthOfLIS(vector<int>& nums) { | ||
int n=nums.size(); | ||
int lis[n]; | ||
lis[0]=1; | ||
for(int i=1;i<n;i++) | ||
{ | ||
lis[i]=1; | ||
for(int j=0;j<i;j++){ | ||
if(nums[i]>nums[j] && lis[i]<lis[j]+1) | ||
lis[i]=lis[j]+1; | ||
} | ||
} | ||
return *max_element(lis,lis+n); | ||
} | ||
|
18 changes: 18 additions & 0 deletions
18
Day-17/Q1:Determine if two strings are close/Subh_Krishna_solution.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
bool closeStrings(string word1, string word2) { | ||
int cnt1[26]{}; | ||
int cnt2[26]{}; | ||
for (char& c : word1) { | ||
++cnt1[c - 'a']; | ||
} | ||
for (char& c : word2) { | ||
++cnt2[c - 'a']; | ||
} | ||
for (int i = 0; i < 26; ++i) { | ||
if ((cnt1[i] == 0) != (cnt2[i] == 0)) { | ||
return false; | ||
} | ||
} | ||
sort(cnt1, cnt1 + 26); | ||
sort(cnt2, cnt2 + 26); | ||
return equal(cnt1, cnt1 + 26, cnt2); | ||
} |
25 changes: 25 additions & 0 deletions
25
Day-18/q2: Search in Rotated Sorted Array/Shubh_Krishna_solution.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
int search(vector<int>& nums, int t) { | ||
int ans=0,l=0,r=nums.size()-1,mid=0; | ||
int n=nums.size()-1; | ||
|
||
|
||
while(l<=r){ | ||
mid=(l+r)/2; | ||
if(t==nums[mid]){return mid;} | ||
if(nums[mid]>nums[n]){ | ||
if(t>nums[mid]||t<nums[0]){ | ||
l=mid+1; | ||
}else{ | ||
r=mid-1; | ||
} | ||
}else{ | ||
if(t<nums[mid]||t>nums[n]){ | ||
r=mid-1; | ||
}else{ | ||
l=mid+1; | ||
} | ||
} | ||
} | ||
|
||
return -1; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
int sumOfLeftLeaves(struct TreeNode* root){ | ||
if (!root) | ||
return 0; | ||
|
||
int sum = 0; | ||
if (root->left && !root->left->left && !root->left->right) | ||
sum += root->left->val; | ||
|
||
sum+=sumOfLeftLeaves(root->left); | ||
sum+=sumOfLeftLeaves(root->right); | ||
|
||
return sum; | ||
} |
14 changes: 14 additions & 0 deletions
14
Day-26/q2: Score of Parentheses/Shubh_Krishna_solution.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
int scoreOfParentheses(string S) { | ||
stack<int> stack; | ||
int cur = 0; | ||
for (char i : S) | ||
if (i == '(') { | ||
stack.push(cur); | ||
cur = 0; | ||
} | ||
else { | ||
cur += stack.top() + max(cur, 1); | ||
stack.pop(); | ||
} | ||
return cur; | ||
} |