File tree Expand file tree Collapse file tree 1 file changed +32
-0
lines changed Expand file tree Collapse file tree 1 file changed +32
-0
lines changed Original file line number Diff line number Diff line change @@ -53,6 +53,10 @@ mid是一个具体的节点,left和right`递归求出即可`
5353
5454## 代码
5555
56+ * 语言支持:JS,C++
57+
58+ JavaScript Code:
59+
5660``` js
5761/*
5862 * @lc app=leetcode id=94 lang=javascript
@@ -130,4 +134,32 @@ var inorderTraversal = function(root) {
130134};
131135
132136```
137+ C++ Code:
138+
139+ ``` c++
140+ /* *
141+ * Definition for a binary tree node.
142+ * struct TreeNode {
143+ * int val;
144+ * TreeNode *left;
145+ * TreeNode *right;
146+ * TreeNode(int x) : val(x), left(NULL), right(NULL) {}
147+ * };
148+ */
149+ class Solution {
150+ public:
151+ vector<int > inorderTraversal(TreeNode* root) {
152+ vector<TreeNode* > s;
153+ vector<int > v;
154+ while (root != NULL || !s.empty()) {
155+ for (; root != NULL; root = root->left)
156+ s.push_back(root);
157+ v.push_back(s.back()->val);
158+ root = s.back()->right;
159+ s.pop_back();
160+ }
161+ return v;
162+ }
163+ };
164+ ```
133165
You can’t perform that action at this time.
0 commit comments