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)