Skip to content

Commit 058a583

Browse files
committed
Merge branch 'keenbin7-patch'
2 parents b0ffb4d + 3e43c3a commit 058a583

File tree

1 file changed

+6
-10
lines changed

1 file changed

+6
-10
lines changed

src/pascalTriangle/pascalTriangle.II.cpp

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,21 +21,14 @@
2121
using namespace std;
2222

2323
vector<int> getRow(int rowIndex) {
24-
vector<int> v;
25-
for(int i=0; i<rowIndex; i++){
26-
if(i==0){
27-
v.push_back(1);
28-
}else{
29-
v.push_back(0);
30-
}
31-
}
24+
vector<int> v(rowIndex+1, 0);
25+
v[0]=1;
3226

3327
for (int i=0; i<rowIndex; i++){
3428
for(int j=i+1; j>0; j--){
3529
v[j] += v[j-1];
3630
}
3731
}
38-
v.push_back(1);
3932
return v;
4033

4134
}
@@ -51,6 +44,9 @@ void printVector( vector<int> pt)
5144

5245
int main(int argc, char** argv)
5346
{
54-
int n = atoi(argv[1]);
47+
int n = 3;
48+
if (argc>1) {
49+
n = atoi(argv[1]);
50+
}
5551
printVector(getRow(n));
5652
}

0 commit comments

Comments
 (0)