Solution for problem [3Sum]