aboutsummaryrefslogtreecommitdiff
path: root/most_stones_remove.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'most_stones_remove.cpp')
-rw-r--r--most_stones_remove.cpp18
1 files changed, 15 insertions, 3 deletions
diff --git a/most_stones_remove.cpp b/most_stones_remove.cpp
index 5283383..632a7fc 100644
--- a/most_stones_remove.cpp
+++ b/most_stones_remove.cpp
@@ -1,8 +1,18 @@
+// 947. Most Stones Removed with Same Row or Column
#include "leetcode.h"
+/*
+ * on a 2d plane, we place 'n' stones at some integer coordinate points. each
+ * coordinate point may have at most one stone. a stone can be removed if it
+ * shares either the same row or the same column as another stone that has not
+ * been removed. given an array 'stones' of length 'n' where 'stones[i] = [x_i,
+ * y_i]' represents the location of the i'th stone, return the largest possible
+ * number of stones that can be removed
+ */
+
class Solution {
public:
- int removeStones(vvd(int) & stones) {
+ int removeStones(vector<vector<int>> &stones) {
int n = stones.size(), c = 0;
unordered_map<int, vector<int>> rows, cols;
for (int i = 0; i < n; ++i) {
@@ -30,6 +40,8 @@ public:
int main() {
Solution obj;
- vvd(int) stones = {{0, 0}, {0, 1}, {1, 0}, {1, 2}, {2, 1}, {2, 2}};
- cout << obj.removeStones(stones);
+ vvd(int) s1 = {{0, 0}, {0, 1}, {1, 0}, {1, 2}, {2, 1}, {2, 2}},
+ s2 = {{0, 1}, {0, 2}, {1, 1}, {2, 0}, {2, 2}};
+ printf("%d\n", obj.removeStones(s1)); // expect: 5
+ printf("%d\n", obj.removeStones(s2)); // expect: 3
}