1688 just follow the problem description

This commit is contained in:
mhrooz 2023-12-05 15:48:41 +01:00
parent cc9b311081
commit ba57817c74

View File

@ -0,0 +1,24 @@
#include<stdcpp.h>
using namespace std;
class Solution{
public:
int numberOfMatches(int n){
int sum = 0;
while(n!=1){
sum+=n/2;
if(n%2) n+=1;
n/=2;
}
return sum;
}
};
int main(){
Solution sol;
int n;
n = 7;
cout<<sol.numberOfMatches(n)<<endl;
n = 14;
cout<<sol.numberOfMatches(n)<<endl;
return 0;
}