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 16df14f

Browse files
ac 1299
1 parent f8733e8 commit 16df14f

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/*
2+
* Copyright (C) 2020, Saul Lawliet <october dot sunbathe at gmail dot com>
3+
* All rights reserved.
4+
*/
5+
6+
#include "c/data-structures/linked-list.h"
7+
#include "c/test.h"
8+
9+
int getDecimalValue(struct ListNode *head) {
10+
int rtn = 0;
11+
while (head != NULL) {
12+
rtn <<= 1;
13+
rtn += head->val;
14+
head = head->next;
15+
}
16+
return rtn;
17+
}
18+
19+
void test(int expect, const char *s) {
20+
struct ListNode *head = linkedlistParse(s);
21+
EXPECT_EQ_INT(expect, getDecimalValue(head));
22+
linkedlistFree(head);
23+
}
24+
25+
int main(void) {
26+
test(5, "[1,0,1]");
27+
test(0, "[0]");
28+
test(1, "[1]");
29+
test(18880, "[1,0,0,1,0,0,1,1,1,0,0,0,0,0,0]");
30+
test(0, "[0,0]");
31+
32+
return testOutput();
33+
}

‎c/test.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ run() {
4444
if ! gcc -std=c99 -Wall -o "$excute" "$file" $lib -lm; then exit 1; fi
4545
if ! $valgrind "$excute"; then fail_count=$((fail_count+1)); fi
4646
rm "$excute"
47+
rm -rf "$excute.DSYM" # https://github.com/LouisBrunner/valgrind-macos/ 会增加的文件
4748
done
4849
}
4950

0 commit comments

Comments
(0)

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