-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
480aa07
commit 0ead726
Showing
6 changed files
with
126 additions
and
0 deletions.
There are no files selected for viewing
23 changes: 23 additions & 0 deletions
23
leetcode_problemset/problemsets/longestValidParentheses.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,23 @@ | ||
#include <bits/stdc++.h> | ||
using namespace std; | ||
|
||
int longestValidParenthesis(string s) { | ||
stack<int> st; | ||
st.push(-1); | ||
int maxCount = 0; | ||
|
||
for(int i = 0; i < s.length(); ++i) { | ||
if(s[i]=='(') | ||
st.push(i); | ||
else | ||
st.pop(); | ||
|
||
if(st.empty()) | ||
st.push(i); | ||
else | ||
maxCount = max(maxCount, i - st.top()); | ||
|
||
} | ||
|
||
return maxCount; | ||
} |
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,23 @@ | ||
#include <bits/stdc++.h> | ||
using namespace std; | ||
|
||
typedef long long ll; | ||
|
||
bool isPalindrome(int x) { | ||
|
||
if(x < 0) | ||
return false; | ||
|
||
ll ans = 0; | ||
int aux = x; | ||
while(x) { | ||
ans = (10*ans)+(x%10); | ||
x /= 10; | ||
} | ||
|
||
if(ans > INT_MAX or ans < INT_MIN) return false; | ||
if(aux == ans) return true; | ||
|
||
return false; | ||
|
||
} |
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,22 @@ | ||
#include <bits/stdc++.h> | ||
using namespace std; | ||
|
||
vector<int> relativeSortArray(vector<int> &arr1, vector<int> &arr2) { | ||
vector<int> sorted; | ||
int n = arr1.size(), m = arr2.size(); | ||
sort(arr1.begin(), arr1.end()); | ||
for(int i = 0, j = 0; i < m; ++i) { | ||
for(int j = 0; j < n; ++j) { | ||
if(arr1[j] == arr2[i]) { | ||
sorted.emplace_back(arr1[j]); | ||
arr1[j] = -1; | ||
} | ||
} | ||
} | ||
|
||
for(int i = 0; i < n; ++i) | ||
if(arr1[i] != -1) | ||
sorted.emplace_back(arr1[i]); | ||
|
||
return sorted; | ||
} |
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 @@ | ||
#include <bits/stdc++.h> | ||
using namespace std; | ||
|
||
int removeDuplicates(vector<int> &nums) { | ||
set<int> s; | ||
int size = nums.size(); | ||
for(int i = 0; i < size; ++i) | ||
s.insert(nums[i]); | ||
|
||
int i = 0; | ||
for(auto x : s) | ||
nums[i++] = x; | ||
|
||
return s.size(); | ||
} |
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 @@ | ||
#include <bits/stdc++.h> | ||
using namespace std; | ||
|
||
typedef long long ll; | ||
|
||
int reverse(int x) { | ||
ll ans = 0; | ||
while (x) | ||
{ | ||
ans = (ans * 10) + (x % 10); | ||
x /= 10; | ||
} | ||
|
||
if (ans > INT_MAX or ans < INT_MIN) | ||
return 0; | ||
return ans; | ||
} | ||
|
||
int main() { | ||
int value; | ||
cin >> value; | ||
cout << reverse(value) << endl; | ||
|
||
return 0; | ||
} |
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 @@ | ||
#include <bits/stdc++.h> | ||
using namespace std; | ||
|
||
int myAtoi(string s) { | ||
|
||
int ans = 0, size = s.length(); | ||
|
||
// checking if is readable | ||
for(int i = 0; i < size; ++i) | ||
if(isalpha(s[i]) and isalpha(s[i+1])) | ||
return 0; | ||
|
||
for(int i = 0; i < size; ++i) | ||
if(isdigit(s[i])) | ||
ans = ans*10+(s[i]-'0'); | ||
|
||
return s[0]==-1?-ans:ans; | ||
} |