Leetcode Shortest Path Problem Linear