[Codewars] Find heavy ball - level: master

Find heavy ball - level: master

  • Time :
  • Space :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#include<vector>
using namespace std;
unsigned int findBall(Scales scales) {
int w = scales.getWeight({0,1,2},{3,4,5});
if(w == 0) {
return scales.getWeight({6},{7}) == 1 ? 7 : 6;
}
if(w == 1) {
w = scales.getWeight({3},{4});
if(w == 0) return 5;
return w == 1 ? 4 : 3;
}
w = scales.getWeight({0},{1});
if(w == 0) return 2;
return w == 1 ? 1 : 0;
}
Author: Song Hayoung
Link: https://songhayoung.github.io/2023/05/20/PS/Codewars/find-heavy-ball-level-master/
Copyright Notice: All articles in this blog are licensed under CC BY-NC-SA 4.0 unless stating additionally.