Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions homework/max-of-vector/maxOfVector.hpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,20 @@
#pragma once
#include <algorithm>
#include <limits>
#include <vector>

int maxOfVector(const std::vector<int>& vec) {
// TODO: Implement me :)
return {};
// manual solution
// if (vec.empty()) {
// return {};
// }
// int max_value{vec[0]};
// for (const int& num : vec) {
// max_value = std::max(max_value, num);
// }
auto it_max = std::max_element(vec.begin(), vec.end());
if (it_max == vec.end()) {
return 0;
}
return *it_max;
}
1 change: 1 addition & 0 deletions homework/max-of-vector/test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ INSTANTIATE_TEST_SUITE_P(
MaxOfVectorTests,
MaxOfVectorTestFixture,
::testing::Values(
std::make_tuple(std::vector<int>{}, 0),
std::make_tuple(std::vector<int>{0}, 0),
std::make_tuple(std::vector<int>{0, -1}, 0),
std::make_tuple(std::vector<int>{0, 1}, 1),
Expand Down