寻找两个有序数组的中位数 #
题目 #
给定两个大小为 m 和 n 的有序数组 nums1 和 nums2。
请你找出这两个有序数组的中位数,并且要求算法的时间复杂度为 O (log (m + n))。
你可以假设 nums1 和 nums2 不会同时为空。
示例 1:
```
nums1 = [1, 3]
nums2 = [2]
则中位数是 2.0
```
示例 2:
```
nums1 = [1, 2]
nums2 = [3, 4]
则中位数是 (2 + 3)/2 = 2.5
```
There are two sorted arrays nums1 and nums2 of size m and n respectively.
Find the median of the two sorted arrays. The overall run time complexity should be O(log (m+n)).
You may assume nums1 and nums2 cannot be both empty.
Example 1:
```
nums1 = [1, 3]
nums2 = [2]
The median is 2.0
```
Example 2:
```
nums1 = [1, 2]
nums2 = [3, 4]
The median is (2 + 3)/2 = 2.5
```
分析 #
题解 #
---
```c
```
---
```c++
```
---
```c#
```
---
```go
```
---
```java
```
---
```javascript
```
---
```kotlin
```
---
```php
```
---
---
---
```ruby
```
---
```rust
```
---
```scala
```
---
```swift
```
---
```typescript
```
---
叶王 © 2013-2024 版权所有。如果本文档对你有所帮助,可以请作者喝饮料。