From 18ae1ea81ee05c62b325bf91813f7d293228df45 Mon Sep 17 00:00:00 2001 From: Haidong Ji Date: Wed, 12 Jun 2019 20:06:47 -0500 Subject: "is it binary search tree hard" done! not too bad, just allowing the right node being equal or greater. Two modifications to the code was needed. --- src/main/TreeBstCheck.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/main') diff --git a/src/main/TreeBstCheck.java b/src/main/TreeBstCheck.java index 51f33c4..4258306 100644 --- a/src/main/TreeBstCheck.java +++ b/src/main/TreeBstCheck.java @@ -56,14 +56,14 @@ public class TreeBstCheck { } else { int i = keyIndexStack.pop(); if (result.size() > 0) { - if (key[i] <= result.get(result.size()-1)) return false; + if (key[i] < result.get(result.size()-1)) return false; } result.add(key[i]); walkLeft = false; } } else { if (right[currentIndex] != -1) { - if (key[right[currentIndex]] <= key[currentIndex]) return false; + if (key[right[currentIndex]] < key[currentIndex]) return false; currentIndex = right[currentIndex]; keyIndexStack.push(currentIndex); walkLeft = true; -- cgit v1.2.3