mirror of
https://github.com/krahets/hello-algo.git
synced 2026-04-14 02:10:37 +08:00
Simplify struct declarations of C.
Use PascalCase for all structs in C. SImplify n_queens.c Format C code for chapter of graph.
This commit is contained in:
@@ -28,7 +28,7 @@ int climbingStairsBacktrack(int n) {
|
||||
int choices[2] = {1, 2}; // 可选择向上爬 1 或 2 阶
|
||||
int state = 0; // 从第 0 阶开始爬
|
||||
int *res = (int *)malloc(sizeof(int));
|
||||
*res = 0; // 使用 res[0] 记录方案数量
|
||||
*res = 0; // 使用 res[0] 记录方案数量
|
||||
int len = sizeof(choices) / sizeof(int);
|
||||
backtrack(choices, state, n, res, len);
|
||||
int result = *res;
|
||||
|
||||
@@ -36,7 +36,7 @@ int climbingStairsDFSMem(int n) {
|
||||
/* Driver Code */
|
||||
int main() {
|
||||
int n = 9;
|
||||
|
||||
|
||||
int res = climbingStairsDFSMem(n);
|
||||
printf("爬 %d 阶楼梯共有 %d 种方案\n", n, res);
|
||||
|
||||
|
||||
@@ -48,8 +48,10 @@ int main() {
|
||||
int costSize = sizeof(cost) / sizeof(cost[0]);
|
||||
printf("输入楼梯的代价列表为 [");
|
||||
for (int i = 0; i < costSize; i++) {
|
||||
if (i != costSize - 1) printf("%d, ", cost[i]);
|
||||
else printf("%d", cost[i]);
|
||||
if (i != costSize - 1)
|
||||
printf("%d, ", cost[i]);
|
||||
else
|
||||
printf("%d", cost[i]);
|
||||
}
|
||||
printf("]\n");
|
||||
|
||||
|
||||
Reference in New Issue
Block a user