[打卡帖]《LeetCode零基础指南》(第四讲) 数组

Do'ya 2021-11-25 22:13:23

33. 搜索旋转排序数组 - 力扣(LeetCode) (leetcode-cn.com)

int search(int* nums, int numsSize, int target){
    int i,j=-2;
for (i=0;i<numsSize;i++){
    if (nums[i]==target){
        j=i;
    }
}
if (j!=-2)
return j;
else
return -1;
}

81. 搜索旋转排序数组 II - 力扣(LeetCode) (leetcode-cn.com)

bool search(int* nums, int numsSize, int target){
for (int i=0;i<numsSize;i++){
    if (nums[i]==target)
    return true;
}
return false;
}

153. 寻找旋转排序数组中的最小值 - 力扣(LeetCode) (leetcode-cn.com)

int findMin(int* nums, int numsSize){
int low=0,high=numsSize-1;
while (low<high){
    int mid=low+(high-low)/2;
    if (nums[mid]<nums[high]){
        high=mid;
    }
    else{
        low=mid+1;
    }
}
return nums[low];
}

70. 爬楼梯 - 力扣(LeetCode) (leetcode-cn.com)

int climbStairs(int n){
int f[100];
f[0]=f[1]=1;
for (int i=2;i<=n;i++){
    f[i]=f[i-1]+f[i-2];
}
return f[n];
}

509. 斐波那契数 - 力扣(LeetCode) (leetcode-cn.com)

int fib(int n){
    int f;
    if (n==0)
    f=0;
    if (n==1)
    f=1;
    if (n>1)
    f=fib(n-1)+fib(n-2);
    return f;
}

1137. 第 N 个泰波那契数 - 力扣(LeetCode) (leetcode-cn.com)

int tribonacci(int n){
int f[38];
f[0]=0,f[1]=1,f[2]=1;
for (int i=0;i<=n-3;i++)
{
    f[i+3]=f[i]+f[i+1]+f[i+2];
}
return f[n];
}

2006. 差的绝对值为 K 的数对数目 - 力扣(LeetCode) (leetcode-cn.com)

int countKDifference(int* nums, int numsSize, int k){
int count=0;
for (int i=0;i<numsSize;i++){
    for (int j=i+1;j<numsSize;j++){
        if (abs(nums[i]-nums[j])==k)
        count++;
    }
}
return count;
}

LCP 01. 猜数字 - 力扣(LeetCode) (leetcode-cn.com)

int game(int* guess, int guessSize, int* answer, int answerSize){
int count=0,i=0,j=0;
while (i<guessSize){
    if (guess[i]==answer[j]){
        count++;
    }
    i++;
    j++;
}
return count;
}

LCP 06. 拿硬币 - 力扣(LeetCode) (leetcode-cn.com)

int minCount(int* coins, int coinsSize){

int ans=0;

for (int i=0;i<coinsSize;i++){

    ans+=(coins[i]+1)/2;

}

return ans;

}

...全文
82 回复 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

64,173

社区成员

发帖
与我相关
我的任务
社区描述
学习「 算法 」的捷径就是 「 题海战略 」,社区由「 夜深人静写算法 」作者创建,三年ACM经验,校集训队队长,亚洲区域赛金牌,世界总决赛选手。社区提供系统的训练,答疑解惑,面试经验,大厂内推等机会
社区管理员
  • 英雄哪里出来
  • 芝麻粒儿
  • Amy卜bo皮
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

QQ群:480072171

英雄算法交流 8 群

 

试试用AI创作助手写篇文章吧