diff options
Diffstat (limited to '')
-rw-r--r-- | 1046/main.cpp | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/1046/main.cpp b/1046/main.cpp new file mode 100644 index 0000000..5789406 --- /dev/null +++ b/1046/main.cpp @@ -0,0 +1,30 @@ + +#include "header.hpp" +#include <algorithm> + +class Solution { +public: + static int lastStoneWeight(std::vector<int> &stones) { + if (stones.size() == 1) { + return stones[0]; + } + std::sort(stones.begin(), stones.end()); + while (stones[stones.size() - 2] > 0) { + stones[stones.size() - 2] = + std::abs(stones[stones.size() - 1] - stones[stones.size() - 2]); + stones[stones.size() - 1] = 0; + std::sort(stones.begin(), stones.end()); + for (auto &iter : stones) { + std::cout << iter << " " << std::endl; + } + std::cout << "\n"; + } + return stones[stones.size() - 1]; + } +}; + +int main(int argc, char **argv) { + std::vector<int> stones = {2, 7, 4, 1, 8, 1}; + std::cout << Solution::lastStoneWeight(stones); + return 0; +} |