diff --git a/src/main/java/edu/princeton/cs/algs4/TST.java b/src/main/java/edu/princeton/cs/algs4/TST.java index fbcdb77d7..e1e2f4bf9 100644 --- a/src/main/java/edu/princeton/cs/algs4/TST.java +++ b/src/main/java/edu/princeton/cs/algs4/TST.java @@ -153,7 +153,8 @@ private Node put(Node x, String key, Value val, int d) { else if (c > x.c) x.right = put(x.right, key, val, d); else if (d < key.length() - 1) x.mid = put(x.mid, key, val, d+1); else x.val = val; - return x; + if (x.val != null || x.left != null || x.right != null || x.mid != null) return x; + return null; } /**