質問編集履歴
6
質問をわかりやすく変更した
test
CHANGED
@@ -1 +1 @@
|
|
1
|
-
MallocでOver flow がおきます。C言語
|
1
|
+
パスカルの三角形 MallocでOver flow がおきます。C言語
|
test
CHANGED
File without changes
|
5
引数の順ばんが間違えていました。申し訳ありません。
test
CHANGED
File without changes
|
test
CHANGED
@@ -98,6 +98,76 @@
|
|
98
98
|
|
99
99
|
|
100
100
|
|
101
|
+
//修正後のコード
|
102
|
+
|
103
|
+
```C
|
104
|
+
|
105
|
+
|
106
|
+
|
107
|
+
|
108
|
+
|
109
|
+
int** generate(int numRows, int* returnSize , int** returnColumnSizes) {
|
110
|
+
|
111
|
+
|
112
|
+
|
113
|
+
int **q, i, j;
|
114
|
+
|
115
|
+
|
116
|
+
|
117
|
+
*returnSize = numRows;
|
118
|
+
|
119
|
+
q = (int **) malloc (sizeof(int *) * numRows);
|
120
|
+
|
121
|
+
*returnColumnSizes = (int *) malloc (sizeof(int) * numRows);
|
122
|
+
|
123
|
+
|
124
|
+
|
125
|
+
|
126
|
+
|
127
|
+
for (i = 0; i < numRows; i++) {
|
128
|
+
|
129
|
+
(*returnColumnSizes)[i] = i + 1;
|
130
|
+
|
131
|
+
q[i] = (int *) malloc (sizeof(int) * (i + 1));
|
132
|
+
|
133
|
+
q[i][0] = 1;
|
134
|
+
|
135
|
+
q[i][i] = 1;
|
136
|
+
|
137
|
+
|
138
|
+
|
139
|
+
if(i!=0){
|
140
|
+
|
141
|
+
for(j=1; j<i; j++){
|
142
|
+
|
143
|
+
q[i][j] = q[i-1][j-1] + q[i-1][j];
|
144
|
+
|
145
|
+
}
|
146
|
+
|
147
|
+
}
|
148
|
+
|
149
|
+
}
|
150
|
+
|
151
|
+
|
152
|
+
|
153
|
+
return q;
|
154
|
+
|
155
|
+
}
|
156
|
+
|
157
|
+
|
158
|
+
|
159
|
+
|
160
|
+
|
161
|
+
|
162
|
+
|
163
|
+
|
164
|
+
|
165
|
+
|
166
|
+
|
167
|
+
```
|
168
|
+
|
169
|
+
|
170
|
+
|
101
171
|
```Error
|
102
172
|
|
103
173
|
=================================================================
|
4
質問をわかりやすくした
test
CHANGED
@@ -1 +1 @@
|
|
1
|
-
|
1
|
+
MallocでOver flow がおきます。C言語
|
test
CHANGED
File without changes
|
3
エラーの出ている場所を説明しました。
test
CHANGED
File without changes
|
test
CHANGED
@@ -28,15 +28,15 @@
|
|
28
28
|
|
29
29
|
int **q, i, j;
|
30
30
|
|
31
|
-
|
32
|
-
|
33
|
-
*returnSize = numRows;
|
34
|
-
|
35
|
-
*returnColumnSizes = (int *) malloc (sizeof(int) * numRows);
|
36
31
|
|
37
32
|
|
38
33
|
|
34
|
+
|
35
|
+
*returnSize = numRows;
|
36
|
+
|
39
37
|
q = (int **) malloc (sizeof(int *) * numRows);
|
38
|
+
|
39
|
+
|
40
40
|
|
41
41
|
|
42
42
|
|
@@ -44,7 +44,9 @@
|
|
44
44
|
|
45
45
|
|
46
46
|
|
47
|
-
|
47
|
+
printf("%d\n",i);
|
48
|
+
|
49
|
+
|
48
50
|
|
49
51
|
q[i] = (int *) malloc (sizeof(int) * (i + 1));
|
50
52
|
|
@@ -66,9 +68,29 @@
|
|
66
68
|
|
67
69
|
}
|
68
70
|
|
71
|
+
|
72
|
+
|
73
|
+
//この下の3行でエラーが出ています。
|
74
|
+
|
75
|
+
*returnColumnSizes = (int *) malloc (sizeof(int) * numRows);
|
76
|
+
|
77
|
+
for (i = 0; i < numRows; i++)
|
78
|
+
|
79
|
+
(*returnColumnSizes)[i] = i + 1;
|
80
|
+
|
81
|
+
|
82
|
+
|
69
83
|
return q;
|
70
84
|
|
85
|
+
|
86
|
+
|
87
|
+
|
88
|
+
|
71
89
|
}
|
90
|
+
|
91
|
+
|
92
|
+
|
93
|
+
|
72
94
|
|
73
95
|
|
74
96
|
|
2
みやすくしました。
test
CHANGED
File without changes
|
test
CHANGED
@@ -6,7 +6,7 @@
|
|
6
6
|
|
7
7
|
|
8
8
|
|
9
|
-
|
9
|
+
|
10
10
|
|
11
11
|
* Return an array of arrays of size *returnSize.
|
12
12
|
|
@@ -14,7 +14,9 @@
|
|
14
14
|
|
15
15
|
* Note: Both returned array and *columnSizes array must be malloced, assume caller calls free().
|
16
16
|
|
17
|
-
|
17
|
+
|
18
|
+
|
19
|
+
|
18
20
|
|
19
21
|
```C
|
20
22
|
|
@@ -54,7 +56,7 @@
|
|
54
56
|
|
55
57
|
if(i!=0){
|
56
58
|
|
57
|
-
for(
|
59
|
+
for(j=1; j<i; j++){
|
58
60
|
|
59
61
|
q[i][j] = q[i-1][j-1] + q[i-1][j];
|
60
62
|
|
1
問題の要件を追記
test
CHANGED
File without changes
|
test
CHANGED
@@ -5,6 +5,16 @@
|
|
5
5
|
[leetcodeの問題のリンクです](https://leetcode.com/problems/pascals-triangle/)
|
6
6
|
|
7
7
|
|
8
|
+
|
9
|
+
/**
|
10
|
+
|
11
|
+
* Return an array of arrays of size *returnSize.
|
12
|
+
|
13
|
+
* The sizes of the arrays are returned as *returnColumnSizes array.
|
14
|
+
|
15
|
+
* Note: Both returned array and *columnSizes array must be malloced, assume caller calls free().
|
16
|
+
|
17
|
+
*/
|
8
18
|
|
9
19
|
```C
|
10
20
|
|