Skip to content

Commit

Permalink
添加 0035.搜索插入位置.md Scala版本
Browse files Browse the repository at this point in the history
  • Loading branch information
wzqwtt committed May 13, 2022
1 parent 05384d5 commit be5cc13
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion problems/0035.搜索插入位置.md
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,26 @@ func searchInsert(_ nums: [Int], _ target: Int) -> Int {
return right + 1
}
```

### Scala
```scala
object Solution {
def searchInsert(nums: Array[Int], target: Int): Int = {
var left = 0
var right = nums.length - 1
while (left <= right) {
var mid = left + (right - left) / 2
if (target == nums(mid)) {
return mid
} else if (target > nums(mid)) {
left = mid + 1
} else {
right = mid - 1
}
}
right + 1
}
}
```



Expand Down

0 comments on commit be5cc13

Please sign in to comment.