Skip to content

Commit 58505a0

Browse files
committed
add code
1 parent d007471 commit 58505a0

File tree

4 files changed

+73
-3
lines changed

4 files changed

+73
-3
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
.vscode
22
*.class
33
__pycache__
4+
.test
45
# Logs
56
logs
67
*.log

code/173.二叉搜索树迭代器.cpp

+19-3
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
*
44
* [173] 二叉搜索树迭代器
55
*/
6-
6+
#include <list>
7+
using namespace std;
78
// @lc code=start
89
/**
910
* Definition for a binary tree node.
@@ -18,16 +19,31 @@
1819
*/
1920
class BSTIterator {
2021
public:
22+
list<TreeNode*> nodes;
23+
int i = 0;
2124
BSTIterator(TreeNode* root) {
25+
nodes.clear();
26+
md(root);
27+
}
2228

29+
void md(TreeNode* root) {
30+
while (root != nullptr) {
31+
nodes.push_back(root);
32+
root = root->left;
33+
}
2334
}
2435

2536
int next() {
26-
37+
TreeNode* node = nodes.back();
38+
nodes.pop_back();
39+
if (node->right != nullptr) {
40+
md(node->right);
41+
}
42+
return node->val;
2743
}
2844

2945
bool hasNext() {
30-
46+
return nodes.size() > 0;
3147
}
3248
};
3349

code/179.最大数.cpp

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*
2+
* @lc app=leetcode.cn id=179 lang=cpp
3+
*
4+
* [179] 最大数
5+
*/
6+
#include <string>
7+
#include <algorithm>
8+
#include <sstream>
9+
#include <vector>
10+
using namespace std;
11+
12+
// @lc code=start
13+
class Solution {
14+
public:
15+
string largestNumber(vector<int>& nums) {
16+
sort(nums.begin(), nums.end(), [](int x, int y) {
17+
long sx = 10;
18+
long sy = 10;
19+
while (sx <= x) {
20+
sx *= 10;
21+
}
22+
while (sy <= y) {
23+
sy *= 10;
24+
}
25+
return sy * x + y > sx * y + x;
26+
});
27+
if (nums[0] == 0) {
28+
return "0";
29+
}
30+
stringstream ss;
31+
for (int num: nums) {
32+
ss << to_string(num);
33+
}
34+
return ss.str();
35+
}
36+
};
37+
// @lc code=end
38+

code/85.最大矩形.cpp

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/*
2+
* @lc app=leetcode.cn id=85 lang=cpp
3+
*
4+
* [85] 最大矩形
5+
*/
6+
7+
// @lc code=start
8+
class Solution {
9+
public:
10+
int maximalRectangle(vector<vector<char>>& matrix) {
11+
12+
}
13+
};
14+
// @lc code=end
15+

0 commit comments

Comments
 (0)