We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent d7c0728 commit 9057442Copy full SHA for 9057442
src/main/java/com/fishercoder/solutions/_35.java
@@ -18,24 +18,14 @@
18
19
public class _35 {
20
21
- public int searchInsert(int[] A, int target) {
22
- int len = A.length;
23
- if (len == 0) {
24
- return 0;
25
- } else {
26
- for (int i = 0; i < len; i++) {
27
- if (A[0] > target) {
28
29
- } else if (A[len - 1] < target) {
30
- return len;
31
- } else if (A[i] == target) {
32
- return i;
33
- } else if (A[i] < target && A[i + 1] > target) {
34
- return i + 1;
35
- }
+ public int searchInsert(int[] nums, int target) {
+ int len = nums.length;
+ for (int i = 0; i < len; i++) {
+ if (target <= nums[i]) {
+ return i;
36
}
37
38
+ return len;
39
40
41
0 commit comments