LeetCode 第 414 场周赛. T1 - T3
原题链接
简单
作者:
autumn_0
,
2024-09-08 12:08:42
,
所有人可见
,
阅读 2
第一题
class Solution {
public String convertDateToBinary(String date) {
String[] s = date.split("-");
int year = Integer.parseInt(s[0]);
int mouth = Integer.parseInt(s[1]);
int day = Integer.parseInt(s[2]);
String binaryYear = Integer.toBinaryString(year);
String binaryMouth = Integer.toBinaryString(mouth);
String binaryDay = Integer.toBinaryString(day);
return binaryYear + "-" + binaryMouth + "-" + binaryDay;
}
}
第二题
class Solution {
public int maxPossibleScore(int[] start, int d) {
Arrays.sort(start);
int n = start.length;
if(n == 2) return start[1] + d - start[0];
int l = 0, r = Integer.MAX_VALUE;
while(l < r)
{
int mid = l + r + 1 >> 1;
if(check(start, mid, d)) l = mid;
else r = mid - 1;
}
return l;
}
public boolean check(int[] start, int diff, int d)
{
int prev = start[0];
for(int i = 1; i < start.length; i ++ )
{
int low = start[i];
int high = start[i] + d;
if(prev + diff > high) return false;
prev = Math.max(prev + diff, start[i]);
}
return true;
}
}
第三题
class Solution {
public long findMaximumScore(List<Integer> nums) {
long sum = 0;
long mx = 0;
for(int i = 0; i + 1 < nums.size(); i ++ )
{
mx = Math.max(mx, nums.get(i));
sum += mx;
}
return sum;
}
}