FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

057 wangfan by wangfanstar · Pull Request #807 · algorithm001/algorithm · GitHub

Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .cpp  (4) All 1 file type selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
11 changes: 11 additions & 0 deletions Week_03/id_57/leetcode_104_057.cpp
This file contains hidden or 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,11 @@
class Solution {
public:
int maxDepth(TreeNode* root) {

if (root == NULL) return 0;
int left = maxDepth(root->left);
int right = maxDepth(root->right);
return max(left,right) + 1;

}
};
22 changes: 22 additions & 0 deletions Week_03/id_57/leetcode_703_057.cpp
This file contains hidden or 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 @@
class KthLargest {
priority_queue<int, vector<int>, greater<int> > pq;
int k;
public:
KthLargest(int k, vector<int>& nums):k(k) {
for(auto n : nums)
{
pq.push(n);
if(pq.size() > k)
pq.pop();
}

}

int add(int val) {
pq.push(val);
if(pq.size() > k)
pq.pop();
return pq.top();

}
};
20 changes: 20 additions & 0 deletions Week_04/id_57/leetcode_169_057.cpp
This file contains hidden or 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,20 @@
class Solution {
public:
int majorityElement(vector<int>& nums) {
int m = nums[0];
int c = 0;
for(int c = 0,i = 0; i < nums.size();i++)
{
if (c == 0)
{
m = nums[i]; c = 1;
}
else
{
m == nums[i] ? c++ : c--;
}
}
return m;

}
};
34 changes: 34 additions & 0 deletions Week_04/id_57/leetcode_784_057.cpp
This file contains hidden or 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,34 @@
class Solution {
public:
void backtrade(string S, vector<string> &res,int i)
{
if (i > S.length())
{
res.push_back(S);
return;
}
if ((S[i] >= 'A') && (S[i] <= 'Z'))
{
backtrade(S,res,i+1);
S[i] += 32;
backtrade(S,res,i+1);

}
else if ((S[i] >='a') && (S[i] <= 'z'))
{
backtrade(S,res,i+1);
S[i] -= 32;
backtrade(S,res,i+1);

}
else
{
backtrade(S,res,i+1);
}
}
vector<string> letterCasePermutation(string S) {
vector<string> res;
backtrade(S,res,0);
return res;
}
};

Back | FazBrowse Home | New Git URL