GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — leetcode/java/443_String_Compression.java at master · qiyuangong/leetcode Expand file tree/ Copy path443_String_Compression.javaMore file actions 18 lines (18 loc) · 632 Bytes / Copy path443_String_Compression.javaFile metadata and controls18 lines (18 loc) · 632 Bytes 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 class Solution { public int compress(char[] chars) { // https://leetcode.com/problems/string-compression/solution/ int anchor = 0, write = 0; for (int read = 0; read < chars.length; read++) { if (read + 1 == chars.length || chars[read + 1] != chars[read]) { chars[write++] = chars[anchor]; if (read > anchor) { for (char c: ("" + (read - anchor + 1)).toCharArray()) { chars[write++] = c; } } anchor = read + 1; } } return write; } } |
| You are visitor 01402775 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |