Fortune Separation Separation Algorithm, time complexity O (n), space complexity O (1). Lamond

2023-01-20   ES  

The interview a few days ago asked, at the time, no response was reacted. Come back to think about it is very simple =. =

c ++ code is as follows

int* separate(int* iArray,int length)

{

    int front=0;

   int back=length-1;

   while(front<back)

   {

         if((iArray[front]&1)==0)

         {

               if(!((iArray[back]&1)==0))

               {

                     int temp=iArray[back];

                     iArray[back]=iArray[front];

                     iArray[front]=temp;front++;back–;

              }else back–;

          }else front++;

     }

    return iArray;

}

source

Random Posts

1231 -Coin Change (i) (simple DP) ZSGG

Integration SSM

7-1 Positive integer A+B (15 points) Mercury

3G, 4G mobile data network business process

Qualcomm platform read and write NV summary