标签:pytho list 逻辑 merge 代码 核心 lis break class
main(){ List a = [0,2,0,2]; a = merge(a); print(a); } merge(List arr){ var i, nextI, len, m; len = arr.length; for(i=0; i<len; i++){ nextI = -1; for(m=i+1; m<len; m++){ if(arr[m]!=0){ nextI = m; break; } } if(nextI!=-1){ if(arr[i]==0){ arr[i] = arr[nextI]; arr[nextI] = 0; i -= 1; }else if(arr[i]==arr[nextI]){ arr[i] = arr[i] * 2; arr[nextI] = 0; } } } return arr; }
标签:pytho list 逻辑 merge 代码 核心 lis break class
原文地址:https://www.cnblogs.com/pythonClub/p/10878164.html