You are viewing a single comment's thread. Return to all comments →
I came up with a similar logic but your code helped me figure out where I went wrong. For peeps who want to see how this is done in C++:
while (!(h11.empty() || h22.empty() || h33.empty())) { if (h11.top() == h22.top() && h33.top() == h11.top()) { cout << h11.top(); return 0; break; } while (h11.top() > h22.top() || h11.top() > h33.top()) { h11.pop(); if (h11.empty()) { cout << 0; return 0; } } while (h22.top() > h11.top() || h22.top() > h33.top()) { h22.pop(); if (h22.empty()) { cout << 0; return 0; } } while (h33.top() > h22.top() || h33.top() > h22.top()) { h33.pop(); if (h33.empty()) { cout << 0; return 0; } } }
Equal Stacks
You are viewing a single comment's thread. Return to all comments →
I came up with a similar logic but your code helped me figure out where I went wrong. For peeps who want to see how this is done in C++: