diff options
Diffstat (limited to 'magnetic_force_2_balls.cpp')
-rw-r--r-- | magnetic_force_2_balls.cpp | 17 |
1 files changed, 14 insertions, 3 deletions
diff --git a/magnetic_force_2_balls.cpp b/magnetic_force_2_balls.cpp index af40160..8416deb 100644 --- a/magnetic_force_2_balls.cpp +++ b/magnetic_force_2_balls.cpp @@ -1,5 +1,16 @@ +// 1552. Magnetic Force Between Two Balls #include "leetcode.h" +/* + * in the universe earth c-137 rick discovered a special form of magnetic force + * between two balls if they are put in his new invented basket. rick has 'n' + * empty baskets the i'th basket is at 'position[i]', more has 'm' ball and + * needs to distribute the balls into the baskets such that the minimum magnetic + * force between any two balls is maximum. rick stated that magnetic force + * betweeen two different balls at positions 'x' and 'y' is '|x - y|'. given the + * integer array 'position' and the integer 'm', return the required force. + */ + class Solution { public: int maxDistance(vector<int> &position, int m) { @@ -29,7 +40,7 @@ private: int main() { Solution obj; - vector<int> position = {1, 2, 3, 4, 7}; - int m = 3; - cout << obj.maxDistance(position, m); + vector<int> p1 = {1, 2, 3, 4, 7}, p2 = {5, 4, 3, 2, 1, 1000000000}; + printf("%d\n", obj.maxDistance(p1, 3)); // expect: 3 + printf("%d\n", obj.maxDistance(p2, 2)); // expect: 999999999 } |