diff --git a/problems/0035.搜索插入位置.md b/problems/0035.搜索插入位置.md index 9a770703..3e8cf5c8 100644 --- a/problems/0035.搜索插入位置.md +++ b/problems/0035.搜索插入位置.md @@ -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 + } +} +```