Re: [閒聊] 每日LeetCode

作者: Neuenmuller (蘇菲・諾伊恩謬拉)   2023-12-09 12:09:01
連三天都是easy爛題是怎樣 = =
https://leetcode.com/problems/binary-tree-inorder-traversal/
這個我就跳過解釋直接付code
class Solution {
public:
vector<int> inorderTraversal(TreeNode* root) {
vector<int> output;
stack<TreeNode*> temp;
TreeNode* cur = root;
while (!temp.empty() || cur) {
while (cur) {
temp.push(cur);
cur = cur->left;
}
cur = temp.top();
temp.pop();
output.push_back(cur->val);
cur = cur->right;
}
return output;
}
};
作者: SecondRun (雨夜琴聲)   2023-12-09 12:11:00
大師
作者: JIWP (JIWP)   2023-12-09 12:54:00
這個月都easy 欸 好爽
作者: NTUEE2CS (EE轉CS)   2023-12-09 13:11:00
大師

Links booklink

Contact Us: admin [ a t ] ucptt.com