From f855a8150dcc9e87095510c28a50b8e24dc91628 Mon Sep 17 00:00:00 2001 From: DMohanty99 <153891601+DMohanty99@users.noreply.github.com> Date: Tue, 17 Sep 2024 00:45:24 +0530 Subject: [PATCH] Create LegacyMonitorBinaryAutocomplete.cpp link:- https://leetcode.com/discuss/interview-question/810154/binary-autocomplete --- LegacyMonitorBinaryAutocomplete.cpp | 86 +++++++++++++++++++++++++++++ 1 file changed, 86 insertions(+) create mode 100644 LegacyMonitorBinaryAutocomplete.cpp diff --git a/LegacyMonitorBinaryAutocomplete.cpp b/LegacyMonitorBinaryAutocomplete.cpp new file mode 100644 index 0000000..a4418f7 --- /dev/null +++ b/LegacyMonitorBinaryAutocomplete.cpp @@ -0,0 +1,86 @@ +// Online C++ compiler to run C++ program online +#include +#include +#include +using namespace std; +typedef struct Trie { + public: + Trie*left=nullptr; + Trie*right=nullptr; + int val=0; + Trie(int num){ + val=num; + } +} Trie; + +vector helper(vectors){ + vectorres; + Trie* head= new Trie(0); + for(int i=0;ival; + for(int j=0;jleft!=nullptr){ + cur=cur->left; + num=cur->val; + }else{ + f=true; + break; + } + }else{ + if(cur->right!=nullptr){ + cur=cur->right; + num=cur->val; + }else{ + f=true; + break; + } + } + + } + res.push_back(num); + } + cur=head; + head->val=i+1; + + for(int j=0;jleft!=nullptr){ + cur=cur->left; + cur->val=i+1; + }else{ + cur->left=new Trie(i+1); + cur=cur->left; + } + }else{ + if(cur->right!=nullptr){ + cur=cur->right; + cur->val=i+1; + }else{ + cur->right=new Trie(i+1); + cur=cur->right; + } + } + } + + } + return res; +} + +int main() { + // Write C++ code here + vectorin{"000","1110","01","001","110","11"}; + vectorin1{"10110100","1011","10110001"}; + auto res= helper(in1); + for(auto y:res){ + cout<