Skip to content

1753. Maximum Score From Removing Stones 👍

  • Time: $O(n)$
  • Space: $O(1)$
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
class Solution {
 public:
  int maximumScore(int a, int b, int c) {
    // the maximum <= the minimum + the middle
    const int x = (a + b + c) / 2;
    // the maximum > the minimum + the middle
    const int y = a + b + c - max({a, b, c});
    return min(x, y);
  }
};
1
2
3
4
5
6
7
8
9
class Solution {
  public int maximumScore(int a, int b, int c) {
    // the maximum <= the minimum + the middle
    final int x = (a + b + c) / 2;
    // the maximum > the minimum + the middle
    final int y = a + b + c - Math.max(a, Math.max(b, c));
    return Math.min(x, y);
  }
}