aboutsummaryrefslogtreecommitdiffstats
path: root/1046/main.cpp
diff options
context:
space:
mode:
authorterminaldweller <thabogre@gmail.com>2022-04-07 05:00:30 +0000
committerterminaldweller <thabogre@gmail.com>2022-04-07 05:00:30 +0000
commitb151bcc3f28cafe64460495f7cbb61444d7f7a9f (patch)
tree2016de2cfd5723f2dcaa045957599ec067e900e6 /1046/main.cpp
parentupdate (diff)
downloadleetcode-b151bcc3f28cafe64460495f7cbb61444d7f7a9f.tar.gz
leetcode-b151bcc3f28cafe64460495f7cbb61444d7f7a9f.zip
update
Diffstat (limited to '')
-rw-r--r--1046/main.cpp30
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;
+}