当前位置:网站首页>【剑指offer】第一题 第二题
【剑指offer】第一题 第二题
2022-08-09 22:56:00 【tt142】
本系列将会不定时更新剑指offer一书,牛客网的题目解析
致力于用流程图和画图解释清楚思路
1.
/**
* 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
*
*
* @param numbers int整型一维数组
* @param numbersLen int numbers数组长度
* @return int整型
*
* C语言声明定义全局变量请加上static,防止重复定义
*/
int duplicate(int* numbers, int numbersLen ) {
if(numbersLen!=0)
{ for(int i=0;i<numbersLen;i++){
if(numbers[i]>numbersLen-1||numbers[i]<0)
return -1;
}
int* p=numbers;
int i=numbersLen;
int count=0;
int j,c;
for(int c=0;c<i;c++){
for( j=1;j<numbersLen-c;j++){
if(*p==*(p+j))
goto flag;
count++;
}
p++;
}
flag:return *p;
if(count==j*c)
return 0;
}
else
return -1;
}
2.
/**
* 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
*
*
* @param target int整型
* @param array int整型二维数组
* @param arrayRowLen int array数组行数
* @param arrayColLen int* array数组列数
* @return bool布尔型
*
* C语言声明定义全局变量请加上static,防止重复定义
*/#include<stdbool.h>
bool Find(int target, int** array, int arrayRowLen, int* arrayColLen ) {
// write code here
int row=0;int cols=*arrayColLen-1;
if(target<array[0][0]||target>array[arrayRowLen-1][cols])
return false ;
while(row<arrayRowLen&&cols>=0){
if(target==array[row][cols])
return true ;
else if(target>array[row][cols])
row++;
else
cols--;
}
return false;
}
创作不易,感谢观看
边栏推荐
- Pinduoduo store operation must know to leave a little knowledge of operation
- IT传奇人物菲尔德的转型经验教训及给CIO的建议
- FreeRTOS任务基础
- [Interface Test] Decoding the request body string of the requests library
- 防火墙之系统防护
- 南大通用数据库-Gbase-8a-学习-04-部署分布式集群
- Technology feast!Huayun Data brings six topics to OpenInfra Days China
- Eureka自我保护
- Dry goods!Towards robust test-time adaptation
- 多商户商城系统功能拆解25讲-平台端分销申请
猜你喜欢
数字孪生智慧制造生产线项目实施方案,平台认知与概念
How to know the computer boot record?
Dry goods!Towards robust test-time adaptation
Live Preview | ICML 2022 11 first-author scholars share online neural network, graph learning and other cutting-edge research
【集训DAY3】挖金矿【二分答案】
微信小程序获取微信用户步数
【集训DAY4】异或【字典树】
Eureka protects itself
ES6 从入门到精通 # 15:生成器 Generator 的用法
ES6 Beginner to Mastery #15: Generator Usage
随机推荐
【JZOF】82二叉树中和为某一值的路径(一)
直播app开发搭建,flutter 实现自适应、自动换行、相对布局
多商户商城系统功能拆解24讲-平台端分销会员
上交所实时行情文件汇总
Linux安装Oracle和postgrepSQL数据库
YOLOV5 study notes (7) - training your own data set
了解什么是架构基本概念和架构本质
Gumbel distribution of discrete choice model
AirFlow介绍
NTU General Database-Gbase-8a-Learning-04-Deploying Distributed Clusters
力扣:377. 组合总和 Ⅳ
Technology feast!Huayun Data brings six topics to OpenInfra Days China
【集训DAY3】中位数
Eureka protects itself
源码编译安装LAMP和LNMP
How to know the computer boot record?
In-depth understanding of multithreading (Part 1)
Comprehensive analysis of FPGA basics
complete knapsack theory
CAD 截断线段