2 Star 10 Fork 2

CG国斌 / myleetcode

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
OrderSearch.java 701 Bytes
一键复制 编辑 原始数据 按行查看 历史
CG国斌 提交于 2021-02-02 14:16 . bytedance
package com.hit.basinfo.search_algorithm;
/**
* author:Charies Gavin
* date:2019/1/7,15:00
* https:github.com/guobinhit
* description: 顺序搜索
*/
public class OrderSearch {
/**
* 顺序搜索
*
* @param nums 待搜索数组
* @param target 目标元素
* @return 目标元素的索引
*/
public int orderSearch(int[] nums, int target) {
if (nums == null) {
return -1;
}
if (nums.length < 2 && nums[0] != target) {
return -1;
}
for (int i = 0; i < nums.length - 1; i++) {
if (nums[i] == target) {
return i;
}
}
return -1;
}
}
Java
1
https://gitee.com/guobinhit/myleetcode.git
git@gitee.com:guobinhit/myleetcode.git
guobinhit
myleetcode
myleetcode
master

搜索帮助