@@ -90,7 +90,7 @@ void make_buff(node_t *node, char *buff, int *l) {
90
90
if (p && p -> entry_cnt > 0 ) {
91
91
p -> entry_cnt -- ;
92
92
if (p -> entry_cnt == 0 ) {
93
- buff [(* l ) ++ ] = 'a' + p -> key ;
93
+ buff [(* l ) ++ ] = 'a' + p -> key - 1 ;
94
94
make_buff (p , buff , l );
95
95
}
96
96
}
@@ -110,11 +110,7 @@ char* alienOrder(char** words, int wordsSize) {
110
110
buff = calloc (27 , sizeof (char )); // include a null terminator
111
111
//assert(buff);
112
112
113
- for (i = 0 ; i < 26 ; i ++ ) {
114
- node [i ].key = -1 ;
115
- }
116
-
117
- root .key = 31 ;
113
+ root .key = 30 ;
118
114
root .entry_cnt = 1 ;
119
115
120
116
// build prefix tree
@@ -133,11 +129,11 @@ char* alienOrder(char** words, int wordsSize) {
133
129
p2 = & node [c2 ];
134
130
if (!p1 -> child [c2 ]) { // make c2 as a child of c1
135
131
p1 -> child [c2 ] = p2 ;
136
- p2 -> key = c2 ;
132
+ p2 -> key = c2 + 1 ;
137
133
p2 -> entry_cnt ++ ;
138
- if (p1 -> key == -1 ) { // put c1 into the tree
134
+ if (p1 -> key == 0 ) { // put c1 into the tree
139
135
root .child [c1 ] = p1 ;
140
- p1 -> key = c1 ;
136
+ p1 -> key = c1 + 1 ;
141
137
p1 -> entry_cnt ++ ;
142
138
}
143
139
}
@@ -153,9 +149,9 @@ char* alienOrder(char** words, int wordsSize) {
153
149
while (s1 [j ]) {
154
150
c1 = s1 [j ] - 'a' ;
155
151
p1 = & node [c1 ];
156
- if (p1 -> key == -1 ) {
152
+ if (p1 -> key == 0 ) {
157
153
root .child [c1 ] = p1 ;
158
- p1 -> key = c1 ;
154
+ p1 -> key = c1 + 1 ;
159
155
p1 -> entry_cnt = 1 ;
160
156
}
161
157
j ++ ;
0 commit comments