Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit e0fb352

Browse files
author
Victor
authored
simplified a little.
1 parent 9232a0f commit e0fb352

File tree

1 file changed

+7
-11
lines changed

1 file changed

+7
-11
lines changed

‎269. Alien Dictionary.c

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ void make_buff(node_t *node, char *buff, int *l) {
9090
if (p && p->entry_cnt > 0) {
9191
p->entry_cnt --;
9292
if (p->entry_cnt == 0) {
93-
buff[(*l) ++] = 'a' + p->key;
93+
buff[(*l) ++] = 'a' + p->key-1;
9494
make_buff(p, buff, l);
9595
}
9696
}
@@ -110,11 +110,7 @@ char* alienOrder(char** words, int wordsSize) {
110110
buff = calloc(27, sizeof(char)); // include a null terminator
111111
//assert(buff);
112112

113-
for (i = 0; i < 26; i ++) {
114-
node[i].key = -1;
115-
}
116-
117-
root.key = 31;
113+
root.key = 30;
118114
root.entry_cnt = 1;
119115

120116
// build prefix tree
@@ -133,11 +129,11 @@ char* alienOrder(char** words, int wordsSize) {
133129
p2 = &node[c2];
134130
if (!p1->child[c2]) { // make c2 as a child of c1
135131
p1->child[c2] = p2;
136-
p2->key = c2;
132+
p2->key = c2+1;
137133
p2->entry_cnt ++;
138-
if (p1->key == -1) { // put c1 into the tree
134+
if (p1->key == 0) { // put c1 into the tree
139135
root.child[c1] = p1;
140-
p1->key = c1;
136+
p1->key = c1+1;
141137
p1->entry_cnt ++;
142138
}
143139
}
@@ -153,9 +149,9 @@ char* alienOrder(char** words, int wordsSize) {
153149
while (s1[j]) {
154150
c1 = s1[j] - 'a';
155151
p1 = &node[c1];
156-
if (p1->key == -1) {
152+
if (p1->key == 0) {
157153
root.child[c1] = p1;
158-
p1->key = c1;
154+
p1->key = c1+1;
159155
p1->entry_cnt = 1;
160156
}
161157
j ++;

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /