forked from DaleStudy/leetcode-study
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathyeonguchoe.go
More file actions
33 lines (29 loc) · 833 Bytes
/
yeonguchoe.go
File metadata and controls
33 lines (29 loc) · 833 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
type Codec struct {
}
// Encodes a list of strings to a single string.
func (codec *Codec) Encode(strs []string) string {
var temp []rune
for _, v := range strs {
var current_string = []rune(v)
temp = append(temp, rune(len(current_string)))
temp = append(temp, rune('π'))
temp = append(temp, current_string...)
}
return string(temp)
}
// Decodes a single string to a list of strings.
func (codec *Codec) Decode(strs string) []string {
var full_string = []rune(strs)
var result []string
var index = 0
for index < len(full_string) {
var word_start int = int(index)
for full_string[word_start] != rune('π') {
word_start += 1
}
length := int(full_string[word_start-1])
result = append(result, string(full_string[word_start+1:word_start+1+length]))
index = word_start + 1 + length
}
return result
}