DavidHo
BAN USERIn-order traversal solution, O(1) space. you only need to remember the previous visited node.
struct Node {
Node* left, *right;
int val;
};
//global variable
bool foundFirst = false;
int previous = 0;
bool isBST(Node* root) {
if (root == NULL) return true;
if(isBST(root->left) ){
if(!foundFirst) {
foundFirst = true;
} else {
if (root->val < previous)
return false;
}
}
previous = root->val;
return isBST(root->right);
}
}
concept
system::button_pushed(int id) {
Button *button = getButton(id); //button is of type ButtonA
Theme *theme = getCurrTheme();
button->pushed(theme);
}
ButtonA::pushed(Theme* t) {
t->ButtonPushed(*this); //Now can use static overload binding, since type of *this
// is always ButtonA
// or simply t->ButtonAPushed(*this); to designate which function to call
}
I don't think you can compute this if order in P is not specified. The order in P must be P1 = x1+x2, P2 = x1+x3, P3 = x1+x4... P_last = x(n-1) + xn.
- DavidHo April 26, 2016Otherwise, each permutation of the P could give a set of xk solution.