IT评测·应用市场-qidao123.com
标题:
LeetCode_单周赛_332
[打印本页]
作者:
火影
时间:
2023-2-12 19:39
标题:
LeetCode_单周赛_332
6354. 找出数组的串联值
题意
将数组首尾元素接在一起,就是串联值。
串联之后删除,如果只剩下一个元素,加上这个元素即可
双指针,从首和尾向中间移动即可
code
注意:
用 long
没看题目用了 int wa了一发
class Solution {
public long findTheArrayConcVal(int[] nums) {
int n = nums.length;
int l = 0, r = n - 1;
long ans = 0;
while (l < r) {
String s = "";
s += nums[l++];
s += nums[r--];
ans += Integer.parseInt(s);
}
if (l == r) ans += nums[l];
return ans;
}
}
复制代码
6355. 统计公平数对的数目
题意
给定 lower 和 upper 找到 数组中 两个不同的数字,如果满足 lower
欢迎光临 IT评测·应用市场-qidao123.com (https://dis.qidao123.com/)
Powered by Discuz! X3.4