public static boolean isValidBST(TreeNode root) {
		if (root == null) {
			return true;
		}
		int[] vals = new int[100];
		int idx = 0;
		TreeNode current = root;

		while (current != null) {
			if (idx >= vals.length) {
				vals = Arrays.copyOf(vals, vals.length + 10);
			}
			if (current.left == null) {
				// right can't be null
				vals[idx++] = current.val;
				current = current.right;
			} else {
				TreeNode p = current.left;
				while (p.right != null && p.right != current) {
					p = p.right;
				}

				if (p.right == null) {
					p.right = current;
					current = current.left;
				} else {
					p.right = null;

					// parent can't be null here, it is the leftest one in the
					// path
					vals[idx++] = current.val;
					current = current.right;
				}
			}
		}

		for (int i = 1; i < idx; i++) {
			int x = vals[i - 1];
			int y = vals[i];
			if (x >= y) {
				return false;
			}
		}
		return true;
	}