Redian新闻
>
问leetcode上一题Merge Sorted Array
avatar
问leetcode上一题Merge Sorted Array# JobHunting - 待字闺中
f*4
1
Given two sorted integer arrays A and B, merge B into A as one sorted array.
Note:
You may assume that A has enough space to hold additional elements from B.
The number of elements initialized in A and B are m and n respectively.
Note里说,A有额外空间,用来合并。
但我觉得必须额外开一个m的空间,除了A[m+n]外,放一些需要swap的变量。
这题最小的空间复杂度能到多少?
avatar
d*e
2
不需要额外的空间

array.

【在 f*******4 的大作中提到】
: Given two sorted integer arrays A and B, merge B into A as one sorted array.
: Note:
: You may assume that A has enough space to hold additional elements from B.
: The number of elements initialized in A and B are m and n respectively.
: Note里说,A有额外空间,用来合并。
: 但我觉得必须额外开一个m的空间,除了A[m+n]外,放一些需要swap的变量。
: 这题最小的空间复杂度能到多少?

avatar
l*c
3
从后往前merge就不需要其他space了,困困。

array.

【在 f*******4 的大作中提到】
: Given two sorted integer arrays A and B, merge B into A as one sorted array.
: Note:
: You may assume that A has enough space to hold additional elements from B.
: The number of elements initialized in A and B are m and n respectively.
: Note里说,A有额外空间,用来合并。
: 但我觉得必须额外开一个m的空间,除了A[m+n]外,放一些需要swap的变量。
: 这题最小的空间复杂度能到多少?

avatar
f*4
4
原来如此。。。Thx
差距还好大,赶紧继续练。

【在 l****c 的大作中提到】
: 从后往前merge就不需要其他space了,困困。
:
: array.

avatar
m*6
5
把B里边值插入A种的合适位置,然后A种的元素进行移动

array.

【在 f*******4 的大作中提到】
: Given two sorted integer arrays A and B, merge B into A as one sorted array.
: Note:
: You may assume that A has enough space to hold additional elements from B.
: The number of elements initialized in A and B are m and n respectively.
: Note里说,A有额外空间,用来合并。
: 但我觉得必须额外开一个m的空间,除了A[m+n]外,放一些需要swap的变量。
: 这题最小的空间复杂度能到多少?

相关阅读
logo
联系我们隐私协议©2024 redian.news
Redian新闻
Redian.news刊载任何文章,不代表同意其说法或描述,仅为提供更多信息,也不构成任何建议。文章信息的合法性及真实性由其作者负责,与Redian.news及其运营公司无关。欢迎投稿,如发现稿件侵权,或作者不愿在本网发表文章,请版权拥有者通知本网处理。