[go: nahoru, domu]

Skip to content

Commit

Permalink
update medium
Browse files Browse the repository at this point in the history
  • Loading branch information
lzyrapx committed Jun 27, 2020
1 parent bc68480 commit 7dc3321
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 0 deletions.
18 changes: 18 additions & 0 deletions LeetCode/Medium/0179.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/*
* @Author: zhaoyang.liang
* @Github: https://github.com/LzyRapx
* @Date: 2020-06-27 09:53:45
*/
class Solution {
public:
string largestNumber(vector<int>& nums) {
sort(nums.begin(), nums.end(), [](int a, int b) {
return to_string(a) + to_string(b) > to_string(b) + to_string(a);
});
string ans = "";
for(int i = 0; i < nums.size(); i++) {
ans = ans + to_string(nums[i]);
}
return ans[0] == '0' ? "0": ans;
}
};
21 changes: 21 additions & 0 deletions LeetCode/Medium/0194.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
###
# @Author: zhaoyang.liang
# @Github: https://github.com/LzyRapx
# @Date: 2020-06-27 09:57:31
###
# Read from the file file.txt and print its transposed content to stdout.
awk '
{
for (i = 1; i <= NF; i++) {
if(NR == 1) {
s[i] = $i;
} else {
s[i] = s[i] " " $i;
}
}
}
END {
for (i = 1; s[i] != ""; i++) {
print s[i];
}
}' file.txt
44 changes: 44 additions & 0 deletions LeetCode/Medium/0199.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* @Author: zhaoyang.liang
* @Github: https://github.com/LzyRapx
* @Date: 2020-06-27 13:11:55
*/
/**
* Definition for a binary tree node.
* struct TreeNode {
* int val;
* TreeNode *left;
* TreeNode *right;
* TreeNode() : val(0), left(nullptr), right(nullptr) {}
* TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
* TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}
* };
*/
class Solution {
public:
vector<int> rightSideView(TreeNode* root) {
vector<int>ans;
if(root == NULL) {
return ans;
}
queue<TreeNode*>que;
que.push(root);
while(!que.empty()) {
int sz = que.size();
for(int i = 0; i <sz; i++) {
TreeNode* cur = que.front();
que.pop();
if(i == sz - 1) {
ans.push_back(cur -> val);
}
if(cur -> left) {
que.push(cur -> left);
}
if(cur -> right) {
que.push(cur -> right);
}
}
}
return ans;
}
};

0 comments on commit 7dc3321

Please sign in to comment.