Shortest Path Algorithm Leetcode Java