我们可以在第一层循环中枚举中间的元素k,再用双指针的思想来遍历{i,j}配对。第二层循环里枚举元素i,然后从右往左移动指针j来寻找arr[i]+arr[k]+arr[j]==target.
这里需要注意的是,两个指针移动时需要考虑与arr[i]相同的元素个数count1,与arr[j]相同的元素个数count2。统计时需要加上count1*count2.
GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | |||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | |||||||||||||||||||||
GeezerVison is showing github.com — LeetCode/Two_Pointers/923.3Sum-With-Multiplicity at master · wisdompeak/LeetCode Expand file tree/ Copy path923.3Sum-With-Multiplicity/Directory actionsMore optionsMore optionsDirectory actionsMore optionsMore options/ Copy path923.3Sum-With-Multiplicity/Folders and files
| |||||||||||||||||||||
| You are visitor 01402792 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. | |||||||||||||||||||||