Leetcode Shortest Path Problem Linear Functions