leetcode443-compressed string (double index)

Source: Internet
Author: User

Tag: Res position new calculates count src rounding end color

Because JS is not differentiated between shaping and double, so there will be 0.2 ....

Number.isinteger

1 Take-Over

Remember it, decimal to 1 to take the remainder is its own

But in fact, besides 1, she was herself.

Because you can not remove the bottom, so and Java will have different effects, very annoying

Finally use down rounding!

If only the return value is needed, that's fine.

Look at the wrong topic, did not expect him to change in the original array

varCompress =function(chars) {if(chars.length<=1)        returnchars.length; //record the current character    varCurrent = Chars[0]; //Record return length    varresult = 0; //record the current number of characters    varCount = 1;  for(Let I=1,len = chars.length;i<len;i++) {Let temp=Chars[i]; //encounter a character that is not the same as before, end the calculation        if(temp!=Current ) {            //this character counts as a position .result++; //More than 1 to calculate            if(count>1){                 while(count>0) {result++; Count= Math.floor (COUNT/10);                }            }                        //Current becomes the nextCurrent =temp; Count= 1; }Else{Count++; }    }    //Finally, if all is repeated, jumps directly, may not calculate toresult++; //More than 1 to calculate      if(count>1){       while(count>0) {result++; Count= Math.floor (COUNT/10);        }      }     returnresult;};

Use a variable to record where you can plug in.

Impossible to cover.

Because the numbers are inserted only in the repeating number position.

The continuation traversal of the traversal

varCompress =function(chars) {if(chars.length<=1)        returnchars.length; //record the current character    varCurrent = Chars[0]; //record where you can plug in.    varindex = 0; //record the current number of characters    varCount = 1; //Debugger;     for(Let I=1,len = chars.length;i<len;i++) {Let temp=Chars[i]; if(temp!=Current ) {Chars[index++] =Current ; Let arr=NewArray (); if(count>1){             while(count>0) {Arr.push (Count%10); Count= Math.floor (COUNT/10);            }             for(Let j=arr.length-1;j>=0;j--) {Chars[index++]=arr[j].tostring (); }} Current=temp; Count= 1; }Else{Count++; }    }    //Finally, if all is repeated, jumps directly, may not calculate tochars[index++] =Current ; Let arr=NewArray (); if(count>1){       while(count>0) {Arr.push (Count%10); Count= Math.floor (COUNT/10);      }       for(Let j=arr.length-1;j>=0;j--) {Chars[index++]=arr[j].tostring (); }    }    returnindex;};

leetcode443-compressed string (double index)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.