2022年1月22日 星期六

947, Most stones remove with same row or column


====
947, Most stones remove with same row or column

====
1. 給予n個stones(雖然每個是座標)
因此給予一個root[n] 存放stone的root
//不要被座標混淆

2. 一樣初值n 假設每個stone單元都是獨立

3. for, for go through
每個stone, 與其他後順序的stone, 檢查座標
如果相同則root[j] = I
//是stone順序 //不要被座標混淆

最後for go through root
如果root[i] == i, (表示一個交集)加count

4. result為全部n 減去集合的count(=redundant

====
class Solution {
public removeStone(vec<vec<int>>& stone)
  int n= stone.size(), count= 0
  vec<int> root(n)
  for i-n root[i] = i
  for i; i<n; i++
    for j=i+1; j<n; j++
      if stone[i][0] == stone[j][0] ||
        stone[i][1] == stone[j][1]
          root[j] = i

  for i-n
    if root[i] == i count++
  return n-count


沒有留言:

張貼留言