namespace myjinxin
{using System;using System.Linq;publicclassKata{publicintObtainMaxNumber(int[] arr){var list = arr.ToList();var max = list.Max();var min = list.Min();for(int i = min; i <=max; i++){var begin = list.FindIndex(x => x == i);var end = list.FindLastIndex(x => x == i);if(begin >=0&& end >=0&& begin != end){varadd= list[begin]*2;if(add> max) max =add;
list.RemoveAt(begin);
list.RemoveAt(end-1);
list.Add(add);
i--;}}return max;}}}
namespace myjinxin
{using System;using System.Linq;publicclassKata{publicintObtainMaxNumber(int[] arr){bool isReady =false;// not finished joining equal elementswhile(!isReady){
isReady =true;
Array.Sort(arr);// sort the array so that equal elements are next to each otherfor(int i =0; i < arr.Length -1; i++){if(arr[i]==0)// skip the zeroes{continue;}if(arr[i]== arr[i +1])// found 2 equal elements{
isReady =false;
arr[i]=0;// remove the first
arr[i +1]*=2;// the second doubles}}}return arr.Max();}}}
简单有趣#66:获取最大数量【难度:2级】:答案1:namespace myjinxin { using System.Collections.Generic; using System.Linq; public class Kata { public int ObtainMaxNumber( int[] arr ) { var...