leetcode-easy-listnode-88 Merge Sorted Array-NO
mycode
不会。。。。。。。。。。。
参考
思路:从后往前计算,这样不会覆盖nums1中的有效值
由于
- You may assume that nums1 has enough space (size that is greater or equal to m + n) to hold additional elements from nums2.所以相当于自己去控制最大下标就是m-1+n
class Solution(object):
def merge(self, nums1, m, nums2, n):
"""
:type nums1: List[int]
:type m: int
:type nums2: List[int]
:type n: int
:rtype: None Do not return anything, modify nums1 in-place instead.
"""
while m > 0 and n > 0:
if nums1[m-1] < nums2[n-1]:
nums1[m-1+n] = nums2[n-1]
n = n - 1
else:
nums1[m-1+n] = nums1[m-1]
m = m - 1
if m == 0 and n> 0:
nums1[:n] = nums2[:n]
leetcode-easy-listnode-88 Merge Sorted Array-NO的更多相关文章
- LeetCode练题——88. Merge Sorted Array
1.题目 88. Merge Sorted Array——Easy Given two sorted integer arrays nums1 and nums2, merge nums2 into ...
- 【leetcode❤python】 88. Merge Sorted Array
#-*- coding: UTF-8 -*-class Solution(object): def merge(self, nums1, m, nums2, n): "& ...
- 【easy】88. Merge Sorted Array 合并两个有序数组
合并两个有序的list 把排序好的nums2插入nums1中,假设nums1这个vector的空间永远是够的 思路:倒序!! class Solution { public: void merge(v ...
- 88. Merge Sorted Array【easy】
88. Merge Sorted Array[easy] Given two sorted integer arrays nums1 and nums2, merge nums2 into nums1 ...
- Leetcode#88. Merge Sorted Array(合并两个有序数组)
题目描述 给定两个有序整数数组 nums1 和 nums2,将 nums2 合并到 nums1 中,使得 num1 成为一个有序数组. 说明: 初始化 nums1 和 nums2 的元素数量分别为 m ...
- [LeetCode] 88. Merge Sorted Array 混合插入有序数组
Given two sorted integer arrays nums1 and nums2, merge nums2 into nums1 as one sorted array. Note: T ...
- 【LeetCode】88. Merge Sorted Array (2 solutions)
Merge Sorted Array Given two sorted integer arrays A and B, merge B into A as one sorted array. Note ...
- LeetCode Array Easy 88. Merge Sorted Array
Description Given two sorted integer arrays nums1 and nums2, merge nums2 into nums1 as one sorted ar ...
- Leetcode 88. Merge Sorted Array(easy)
Given two sorted integer arrays nums1 and nums2, merge nums2 into nums1 as one sorted array. Note:Yo ...
- LeetCode 88. Merge Sorted Array(合并有序数组)
Given two sorted integer arrays nums1 and nums2, merge nums2 into nums1 as one sorted array. Note:Yo ...
随机推荐
- git配置ssh秘钥(公钥以及私钥)linux
本文默认已经安装git,并有github或者gitlab账号 git在linux下安装参考:https://www.cnblogs.com/lz0925/p/10791147.html 在Linux中 ...
- Python基础:深浅拷贝
对于数字.字符串深浅拷贝: import copy num = 0 copy_num = copy.copy(num) print("These are normal copy") ...
- [易学易懂系列|rustlang语言|零基础|快速入门|(18)|use关键词]
[易学易懂系列|rustlang语言|零基础|快速入门|(18)|use关键词] 实用知识 use关键词 我们今天来讲讲use关键词. 1.简单来说,use是给其他方法或资源定义一个别名,然后调用者, ...
- 封装ORM.py与mysql_client.py代码
ORM.py ''' ORM: 对象关系映射 ---> 映射到数据库MySQL中的数据表 类名 ---> 表名 对象 ---> 一条记录 对象.属性 ---> 字段 模拟Dja ...
- qt5--字符串格式拼接
QString str=QString("x坐标为:%1 y坐标为:%2").arg(i).arg(j);
- 树莓派设定笔记(Raspberry Pi 3 B+)
树莓派默认用户名密码 pi / raspberry 一.启用root用户 设置root用户密码 sudo passwd root 开启root账户 sudo passwd --unlock root ...
- 【leetcode】1267. Count Servers that Communicate
题目如下: You are given a map of a server center, represented as a m * n integer matrix grid, where 1 me ...
- 【leetcode】1262. Greatest Sum Divisible by Three
题目如下: Given an array nums of integers, we need to find the maximum possible sum of elements of the a ...
- js new Date() 测试
var t = new Date().toString(); //t = "Thu Oct 31 2019 11:36:57 GMT+0800 (中国标准时间)" var t1 = ...
- Web大文件上传断点续传解决方案
最近遇见一个需要上传百兆大文件的需求,调研了七牛和腾讯云的切片分段上传功能,因此在此整理前端大文件上传相关功能的实现. 在某些业务中,大文件上传是一个比较重要的交互场景,如上传入库比较大的Excel表 ...