MCPcopy Create free account
hub / github.com/austingebauer/go-leetcode / Encode

Method Encode

encode_and_decode_strings_271/solution.go:13–21  ·  view source on GitHub ↗

Encodes a list of strings to a single string.

(strs []string)

Source from the content-addressed store, hash-verified

11
12// Encodes a list of strings to a single string.
13func (codec *Codec) Encode(strs []string) string {
14 var b bytes.Buffer
15 for _, s := range strs {
16 // encode string using length and underscore header
17 l := len(s)
18 b.WriteString(fmt.Sprintf("%d_%s", l, s))
19 }
20 return b.String()
21}
22
23// Decodes a single string to a list of strings.
24func (codec *Codec) Decode(strs string) []string {

Callers 1

TestEncodeAndDecodeFunction · 0.95

Calls

no outgoing calls

Tested by 1

TestEncodeAndDecodeFunction · 0.76