1 Star 0 Fork 0

徐长贺/Leetcode

加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
_35.java 731 Bytes
一键复制 编辑 原始数据 按行查看 历史
Fisher Coder 提交于 2019-10-18 21:40 +08:00 . refactor 35
package com.fishercoder.solutions;
/**
* 35. Search Insert Position
*
* Given a sorted array and a target value,
* return the index if the target is found.
* If not, return the index where it would be if it were inserted in order.
You may assume no duplicates in the array.
Here are few examples.
[1,3,5,6], 5 → 2
[1,3,5,6], 2 → 1
[1,3,5,6], 7 → 4
[1,3,5,6], 0 → 0
*/
public class _35 {
public static class Solution1 {
public int searchInsert(int[] nums, int target) {
int len = nums.length;
for (int i = 0; i < len; i++) {
if (target <= nums[i]) {
return i;
}
}
return len;
}
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/isulong/Leetcode.git
git@gitee.com:isulong/Leetcode.git
isulong
Leetcode
Leetcode
master

搜索帮助