1 Star 0 Fork 0

唐梓迅/leetcode题解

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
.LeetCode 594 489 Bytes
一键复制 编辑 原始数据 按行查看 历史
唐梓迅 提交于 3年前 . 最长和谐子序列
int cmp(const void *e1,const void *e2)
{
return *(int*)e1-*(int*)e2;
}
int findLHS(int* nums, int numsSize){
qsort(nums,numsSize,sizeof(int),cmp);
int begin = 0;
int res = 0;
for (int end = 0; end < numsSize; end++)
{
while (nums[end] - nums[begin] > 1)
{
begin++;
}
if (nums[end] - nums[begin] == 1)
{
res = fmax(res, end - begin + 1);
}
}
return res;
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Java
1
https://gitee.com/Tang-CMer/leetcode-problem-solving.git
git@gitee.com:Tang-CMer/leetcode-problem-solving.git
Tang-CMer
leetcode-problem-solving
leetcode题解
master

搜索帮助