8000 add 704 · shaovoon/Leetcode@170fdf1 · GitHub
[go: up one dir, main page]

Skip to content

Commit 170fdf1

Browse files
add 704
1 parent 5f7c512 commit 170fdf1

File tree

1 file changed

+7
-1
lines changed
  • src/main/java/com/fishercoder/solutions

1 file changed

+7
-1
lines changed

src/main/java/com/fishercoder/solutions/_704.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,13 @@ public int search(int[] nums, int target) {
4141
right = mid - 1;
4242
}
4343
}
44-
return nums[left] == target ? left : (right >= 0 && nums[right] == target) ? right : -1;
44+
if (left <= nums.length && nums[left] == target) {
45+
return left;
46+
}
47+
if (right >= 0 && nums[right] == target) {
48+
return right;
49+
}
50+
return -1;
4551
}
4652
}
4753
}

0 commit comments

Comments
 (0)
0