diff options
author | Jack Sangdahl <[email protected]> | 2025-06-27 12:23:02 -0600 |
---|---|---|
committer | Jack Sangdahl <[email protected]> | 2025-06-27 12:23:02 -0600 |
commit | a96b65cbfad7f62f3db6b2eab105e4e25c0414c5 (patch) | |
tree | e2a2b3f49f9fb741be81415266ac93e74cff42ec /other/max_distance_closest_person.cpp | |
parent | 694ad5ed71edcb1deccab54b72d706b779918276 (diff) | |
download | leetcode-a96b65cbfad7f62f3db6b2eab105e4e25c0414c5.tar.gz leetcode-a96b65cbfad7f62f3db6b2eab105e4e25c0414c5.zip |
chore: remove old cpp and rust solutions
Diffstat (limited to 'other/max_distance_closest_person.cpp')
-rw-r--r-- | other/max_distance_closest_person.cpp | 39 |
1 files changed, 0 insertions, 39 deletions
diff --git a/other/max_distance_closest_person.cpp b/other/max_distance_closest_person.cpp deleted file mode 100644 index a9203fe..0000000 --- a/other/max_distance_closest_person.cpp +++ /dev/null @@ -1,39 +0,0 @@ -// 849. Maximize Distance to Closest Person -#include "leetcode.h" - -/* - * given an array representing a row of 'seats' where 'seats[i] = 1' represents - * a person sitting in the i'th seat, and 'seats[i] = 0' represents that the - * i'th seat is empty (0-indexed). there is at least one empty seat, and at - * least one person sitting. alex wants to sit in the seat such that the - * distance between him and the closest person to him is maximised. return that - * maximum distance to the closest person. - */ - -class Solution { -public: - int maxDistToClosest(vector<int> &seats) { - int n = seats.size(), empty = 0, ans = 0, idx1 = -1, idx2 = -1; - for (int i = 0; i < n; i++) { - if (seats[i] == 1) { - empty = 0; - if (idx1 == -1) - idx1 = i; - idx2 = i; - } else { - empty++; - ans = max(ans, (empty + 1) / 2); - } - } - ans = max({ans, idx1, n - 1 - idx2}); - return ans; - } -}; - -int main() { - Solution obj; - vector<int> s1 = {1, 0, 0, 0, 1, 0, 1}, s2 = {1, 0, 0, 0}, s3 = {0, 1}; - printf("%d\n", obj.maxDistToClosest(s1)); // expect: 2 - printf("%d\n", obj.maxDistToClosest(s2)); // expect: 3 - printf("%d\n", obj.maxDistToClosest(s3)); // expect: 1 -} |