Remove duplicate nodes on the same branch, leaving only the lowest level node