File tree Expand file tree Collapse file tree 1 file changed +32
-0
lines changed
encode-and-decode-strings Expand file tree Collapse file tree 1 file changed +32
-0
lines changed Original file line number Diff line number Diff line change
1
+ /*
2
+ Time Complexity: O(n)
3
+ Space Complexity: O(1)
4
+
5
+ non-ASCII 유니코드 문자를 사용함
6
+
7
+ To-Do : escaping 방법 학습하기
8
+ */
9
+ public class Codec {
10
+
11
+ // Encodes a list of strings to a single string.
12
+ public String encode (List <String > strs ) {
13
+ StringBuilder sb = new StringBuilder ();
14
+ for (int i = 0 ; i < strs .size (); i ++) {
15
+ if (i > 0 ) {
16
+ sb .append ('\u2764' );
17
+ }
18
+ sb .append (strs .get (i ));
19
+ }
20
+
21
+ return sb .toString ();
22
+ }
23
+
24
+ // Decodes a single string to a list of strings.
25
+ public List <String > decode (String s ) {
26
+ return new ArrayList <>(Arrays .asList (s .split ("\u2764 " )));
27
+ }
28
+ }
29
+
30
+ // Your Codec object will be instantiated and called as such:
31
+ // Codec codec = new Codec();
32
+ // codec.decode(codec.encode(strs));
You can’t perform that action at this time.
0 commit comments