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
class Solution { | |
public: | |
int maxArea(vector<int>& height) { | |
int len = height.size(); | |
int l = 0, r = len-1, maxArea = 0; | |
while(l<r) | |
{ | |
if(height[l] <= height[r]) | |
{ | |
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
class Solution { | |
public: | |
string longestCommonPrefix(vector<string>& strs) { | |
int len_s = strs.size(); | |
if(len_s == 0) return ""; | |
for(int j = 0; j < strs[0].size(); j++){ | |
char c = strs[0][j]; | |
for(int i = 0; i < len_s; i++){ | |
//Basically we check two cases: |
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
class Solution { | |
public: | |
string longestCommonPrefix(vector<string>& strs) { | |
int len_s = strs.size(); | |
if(len_s == 0) return ""; | |
string prefix = strs[0]; | |
for(int i = 1; i < len_s; i++){ | |
int minlen = min(prefix.size(), strs[i].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
class Solution { | |
public: | |
string longestCommonPrefix(vector<string>& strs) { | |
int len_s = strs.size(); | |
if(len_s == 0) return ""; | |
return longestCommonPrefix(strs, 0, len_s - 1); | |
} | |
string longestCommonPrefix(vector<string>& strs, int l, int r){ | |
if(l == r){ | |
return strs[l]; |
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
class Solution { | |
public: | |
string longestCommonPrefix(vector<string>& strs) { | |
int len = strs.size(); | |
string finalStr; | |
if(len == 0) return ""; | |
sort(strs.begin(), strs.end()); | |
int n = strs[0].size(); | |
for(int i = 0; i<n; i++) | |
{ |
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
class Solution { | |
public: | |
vector<vector<int>> threeSum(vector<int>& nums) { | |
int len = nums.size(); | |
vector<vector<int>> finalResult; | |
std::sort(nums.begin(), nums.end()); | |
if(len <= 2) | |
return finalResult; | |
for(int i = 0; i < len - 2; i++) |
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
class Solution { | |
public: | |
int threeSumClosest(vector<int>& nums, int target) { | |
int sub = INT_MAX; | |
int sum = 0; | |
int len = nums.size(); | |
for(int i = 0; i < len; i++){ | |
for(int j = i+1; j < len; j++){ | |
for(int k = j+ 1; k < len; k++){ | |
if(abs(nums[i]+nums[j]+nums[k] - target) < sub){ |
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
class Solution { | |
public: | |
int threeSumClosest(vector<int>& nums, int target) { | |
std::sort(nums.begin(), nums.end()); | |
int len = nums.size(); | |
long bestDist = LONG_MAX, bestSum = target; | |
if(len <= 2) | |
return 0; | |
for(int i = 0; i < len-2; i++) |
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
class Solution { | |
public: | |
vector<vector<int>> fourSum(vector<int>& nums, int target) { | |
vector<vector<int>> finalResult; | |
int len = nums.size(); | |
if(len <= 3) | |
return finalResult; | |
else | |
sort(nums.begin(), nums.end()); | |
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
class Solution { | |
private: | |
vector<string> dic_s = {"", "", "abc", "def", "ghi","jkl", "mno","pqrs", "tuv", "wxyz"}; | |
vector<string> result; | |
public: | |
void dfs(const string &digits, string s, int pos){ | |
int len = digits.size(); | |
if(pos >= len){ | |
return; | |
} |