[InterviewBit] Paint House!

Paint House!

  • Time :
  • Space :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
int Solution::solve(vector<vector<int> > &A) {
int r = 0, g = 0, b = 0;
for(auto a : A) {
int rr = min(g,b) + a[0];
int gg = min(r,b) + a[1];
int bb = min(r,g) + a[2];
r = rr;
g = gg;
b = bb;
}

return min({r,g,b});
}

Author: Song Hayoung
Link: https://songhayoung.github.io/2022/11/07/PS/interviewbit/paint-house/
Copyright Notice: All articles in this blog are licensed under CC BY-NC-SA 4.0 unless stating additionally.