leet code algorithm in java