当前位置:网站首页>【剑指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;
}
创作不易,感谢观看
边栏推荐
- complete knapsack theory
- Live Preview | ICML 2022 11 first-author scholars share online neural network, graph learning and other cutting-edge research
- Golden Warehouse Database KingbaseGIS User Manual (6.6. Geometric Object Verification Function, 6.7. Spatial Reference System Function)
- 力扣:377. 组合总和 Ⅳ
- 生成树和交换的总结
- 直播间搭建,按钮左滑出现删除等操作按钮
- 【JZOF】77 Print binary tree in zigzag
- 完全背包理论
- Pinduoduo store operation must know to leave a little knowledge of operation
- Filament-Material 绘制基本图形
猜你喜欢
Wireshark classic practice and interview 13-point summary
源码编译安装LAMP和LNMP
ABAP中Collect的用法
【云原生】一文讲透Kubevela addon如何添加腾讯Crane
Explore the TiDB Lightning source code to solve the found bugs
数据库优化 | 干货
The latest "Grain Academy Development Tutorial" in 2022: 10 - Front-end payment module
【集训DAY3】中位数
A summary of 6 common tools for cross-border e-commerce
ES6 从入门到精通 # 12:数组的扩展方法一
随机推荐
【云原生】一文讲透Kubevela addon如何添加腾讯Crane
【JZOF】77按之字形打印二叉树
AppUser object extension based on ABP
The latest "Grain Academy Development Tutorial" in 2022: 10 - Front-end payment module
直播间搭建,按钮左滑出现删除等操作按钮
位图的基本原理以及应用
NotWritableError: The current user does not have write permissions when conda creates a new environment
Digital wallets, red sea ecological rapid introduction of small programs can help capture device entry wisdom
【SSL集训DAY3】控制棋盘【二分图匹配】
CAD 绘制圆角处理
Qt 之 QDateEdit 和 QTimeEdit
70. 爬楼梯进阶版
【集训DAY5】快速排序【模拟】【数学】
Explore the TiDB Lightning source code to solve the found bugs
【集训DAY5】堆箱子【数学】
【C语言】指针和数组的深入理解(第四期)
Redis-基本介绍/linux下环境配置/配置文件
Eureka自我保护
直播app开发搭建,flutter 实现自适应、自动换行、相对布局
YOLOV5学习笔记(七)——训练自己数据集