Archives
Trending
Support
Login
clear text
XML
Django
JavaScript
MATLAB
C
C++
C#
Python
SQL
Shell
Bash
Markdown
YAML
JSON
HTML
CSS
PHP
Java
Ruby
Go
Rust
Swift
Kotlin
Arduino
TypeScript
Perl
Autohotkey
Lua
SQF
R
Scala
Haskell
Groovy
Dart
Clojure
VB.NET
Objective-C
PowerShell
Bash
CoffeeScript
Verilog
class Solution { public: //Function to return a list of integers denoting the node //values of both the BST in a sorted order. vector
v1, v2; void dfs(Node *root, int t) { if(!root) { return; } dfs(root->left, t); if(t == 1) { v1.push_back(root->data); } else { v2.push_back(root->data); } dfs(root->right, t); } vector
merge(Node *root1, Node *root2) { dfs(root1, 1); dfs(root2, 2); vector
v; int i = 0, j = 0; while(i < (int) v1.size() and j < (int) v2.size()) { if(v1[i] < v2[j]) { v.push_back(v1[i]); i++; } else if(v1[i] > v2[j]) { v.push_back(v2[j]); j++; } else { v.push_back(v1[i]); v.push_back(v1[i]); i++; j++; } } while(i < (int) v1.size()) { v.push_back(v1[i]); i++; } while(j < (int) v2.size()) { v.push_back(v2[j]); j++; } return v; } };
Mark as private (unlisted)
for 30 minutes
for 6 hours
for 1 day
for 1 week
for 1 month
for 1 year
everlasting (like CCCP)