Skip to content

Commit 5f7aeb0

Browse files
committed
Runtime: 4 ms (Top 80.72%) | Memory: 13.8 MB (Top 73.01%)
1 parent 46ade1f commit 5f7aeb0

File tree

1 file changed

+14
-13
lines changed

1 file changed

+14
-13
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,38 @@
1+
// Runtime: 4 ms (Top 80.72%) | Memory: 13.8 MB (Top 73.01%)
12
class Solution {
23
public:
3-
4+
45
bool helper(int &ind, TreeNode *root, vector<int> &voyage, vector<int> &ans){
56
if(root == NULL || ind == voyage.size()){
67
ind--;
78
return true;
89
}
9-
10-
// Not possible to create
10+
11+
// Not possible to create
1112
if(root->val != voyage[ind]){
1213
ans.clear();
1314
ans.push_back(-1);
1415
return false;
1516
}
16-
17+
1718
// If voyage value not equal to its left child, then swap both childs and check
1819
if(root->left && root->left->val != voyage[ind+1]){
19-
TreeNode *temp = root->left;
20-
root->left = root->right;
21-
root->right = temp;
22-
23-
// Pusing root into ans
24-
ans.push_back(root->val);
20+
TreeNode *temp = root->left;
21+
root->left = root->right;
22+
root->right = temp;
23+
24+
// Pusing root into ans
25+
ans.push_back(root->val);
2526
}
26-
27+
2728
return helper(++ind, root->left, voyage, ans) &&
2829
helper(++ind, root->right, voyage, ans);
2930
}
30-
31+
3132
vector<int> flipMatchVoyage(TreeNode* root, vector<int>& voyage) {
3233
int ind = 0;
3334
vector<int> ans;
3435
helper(ind, root, voyage, ans);
3536
return ans;
3637
}
37-
};
38+
};

0 commit comments

Comments
 (0)