Count Pairs Of Nodes Leetcode Problems Java