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/python/443_String_Compression.py at master · qiyuangong/leetcode Expand file tree/ Copy path443_String_Compression.pyMore file actions 18 lines (18 loc) · 627 Bytes / Copy path443_String_Compression.pyFile metadata and controls18 lines (18 loc) · 627 Bytes 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 class Solution(object): def compress(self, chars): """ :type chars: List[str] :rtype: int """ # https://leetcode.com/problems/string-compression/solution/ anchor = write = 0 for read, c in enumerate(chars): if read + 1 == len(chars) or chars[read + 1] != c: chars[write] = chars[anchor] write += 1 if read > anchor: for digit in str(read - anchor + 1): chars[write] = digit write += 1 anchor = read + 1 return write |
| You are visitor 01402792 — 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. |