Shortest Path Problem Leetcode Java