欢迎您访问 最编程 本站为您分享编程语言代码,编程技术文章!
您现在的位置是: 首页

[C++ 算法] 9.四数之和的双_指针图

最编程 2024-10-05 06:58:38
...

nums=[1,0,-1,0,-2,2]

target=0

  1. n=6,i=0,j=1,left=2,right=5,aim=-1

cc34bc0990edc6d3107deb9888d1802b

  1. left<right,sum=-1+2=1>aim,right--

8561104e892c6d5a435b7abae398630c

  1. left<right,sum=-1-2=-3<aim,left++

34a98b82163eb633d10ae3ed2a10f0d7

  1. left<right,sum=0-2=-2<aim,left++

  2. 不满足循环条件,跳出while循环,进入去重2j++

e4ce917585712b312259d149ca9e16ec

  1. n=6,i=0,j=2,left=3,right=5,aim=0

  2. 后面的步骤类似,就不多赘述了。