Skip to content

Commit b58286d

Browse files
Create Balanced Triplet.cpp
1 parent 53a03a2 commit b58286d

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

Balanced Triplet.cpp

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
class Solution {
2+
public:
3+
long long minOps(long long a, long long b, long long c) {
4+
vector<long long>vec;
5+
vec.push_back(a);
6+
vec.push_back(b);
7+
vec.push_back(c);
8+
sort(vec.begin(),vec.end());
9+
10+
long long p=vec[1]-vec[0];
11+
12+
long long q=vec[2]-vec[1];
13+
14+
long long ans=ceil(abs(p-q)/(double)2);
15+
16+
return ans;
17+
}
18+
};
19+
20+
21+
Complexity:
22+
Time Complexity: O(1), As the operations within the check and minOps functions are constant-time operations, involving simple arithmetic and comparison.
23+
Space Complexity: O(1), As we are using constant extra space.

0 commit comments

Comments
 (0)