Two Pointer Leetcode Questions Java