-
1309. Decrypt String from Alphabet to Integer Mapping릿코드(LEETCODE) 2020. 2. 16. 16:38반응형
https://leetcode.com/problems/decrypt-string-from-alphabet-to-integer-mapping/
Source
class Solution { public: string freqAlphabets(string s) { string ret; int size = s.size(); int pos = 0; for (int i = 0; i < size; ) { unsigned char code[3]; code[0] = s[i]; code[1] = code[2] = -1; if (i + 1 < size) code[1] = s[i + 1];; if (i + 2 < size) code[2] = s[i + 2]; if (code[2] == '#') { string d; d.push_back(code[0]); d.push_back(code[1]); ret += 'j' + atoi(d.c_str()) - 10; i += 3; } else { ret += 'a' + code[0] - '1'; i++; } } return ret; } };
반응형'릿코드(LEETCODE)' 카테고리의 다른 글
1207. Unique Number of Occurrences (0) 2020.02.28 1310. XOR Queries of a Subarray (0) 2020.02.16 1352. Product of the Last K Numbers (0) 2020.02.16 1143. Longest Common Subsequence (0) 2020.02.15 119. Pascal's Triangle II (0) 2020.02.14