Re: [閒聊] 每日LeetCode
看板Marginalman作者Neuenmuller (蘇菲・諾伊恩謬拉)時間5月前 (2023/12/09 12:09)推噓1(1推 0噓 2→)留言3則, 3人參與討論串570/719 (看更多)
連三天都是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;
}
};
--
噗尼都會的鍊金術......
如、如果是這個的話,我說不定也能學會!
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 97.99.29.95 (美國)
※ 文章網址: https://www.ptt.cc/bbs/Marginalman/M.1702094953.A.533.html
推
12/09 12:11,
5月前
, 1F
12/09 12:11, 1F
→
12/09 12:54,
5月前
, 2F
12/09 12:54, 2F
→
12/09 13:11,
5月前
, 3F
12/09 13:11, 3F
討論串 (同標題文章)
完整討論串 (本文為第 570 之 719 篇):
閒聊
1
3