Skip to content

Commit 055f3fe

Browse files
author
pezy chen
authored
Merge pull request Mooophy#669 from Hierom/patch-1
Revise redundant version size
2 parents 98665a2 + ca68682 commit 055f3fe

File tree

1 file changed

+2
-3
lines changed

1 file changed

+2
-3
lines changed

ch03/ex3_20b.cpp

+2-3
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,8 @@ int main()
1717
return -1;
1818
}
1919

20-
auto size = ivec.size();
21-
if (size % 2 != 0) size = size / 2 + 1;
22-
else size /= 2;
20+
// If the vector has odd size, element in the middle will add to itself.
21+
auto size = (ivec.size() + 1) / 2;
2322

2423
for (int i = 0; i != size; ++i)
2524
cout << ivec[i] + ivec[ivec.size() - i - 1] << " ";

0 commit comments

Comments
 (0)