【LeetCode系列】Leet Code OJ 88. Merge Sorted Array [Difficulty: Easy]
题目链接
审题!审题!审题!重要的事情说三遍。
看到题目是不是觉得好像很熟悉的样子?然后一不小心就手撸了个归并排序?没错,我就是这样的。
这题感觉应该算是一个插入排序,或者说把Nums2加入到Nums1的队尾然后进行排序。
不过我既然已经把归并排序xiew写完了,那么肯定不会再用投机取巧的方法,算是给自己一个教训把:
class Solution:def merge(self, nums1, m, nums2, n):""":type nums1: List[int]:type m: int:type nums2: List[int]:type n: int:rtype: void Do not return anything, modify nums1 in-place instead."""resu = []st1 = 0st2 = 0for i in range(m + n):if st2 == n or st1 < m and nums1[st1] < nums2[st2]:resu.append(nums1[st1])st1 += 1else:resu.append(nums2[st2])st2 += 1for i in range(m+n):nums1[i] = resu[i]
【LeetCode系列】Leet Code OJ 88. Merge Sorted Array [Difficulty: Easy]相关推荐
- Leet Code OJ 88. Merge Sorted Array [Difficulty: Easy]
题目: Given two sorted integer arrays nums1 and nums2, merge nums2 into nums1 as one sorted array. Not ...
- Leet Code OJ 14. Longest Common Prefix [Difficulty: Easy]
题目: Write a function to find the longest common prefix string amongst an array of strings. 翻译: 写一个函数 ...
- Leet Code OJ 118. Pascal's Triangle [Difficulty: Easy]
题目: Given numRows, generate the first numRows of Pascal's triangle. For example, given numRows = 5, ...
- Leet Code OJ 110. Balanced Binary Tree [Difficulty: Easy]
题目: Given a binary tree, determine if it is height-balanced. For this problem, a height-balanced bin ...
- Leet Code OJ 326. Power of Three [Difficulty: Easy]
题目: Given an integer, write a function to determine if it is a power of three. Follow up: Could you ...
- Leet Code OJ 219. Contains Duplicate II [Difficulty: Easy]
题目: Given an array of integers and an integer k, find out whether there are two distinct indices i a ...
- Leet Code OJ 172. Factorial Trailing Zeroes [Difficulty: Easy]
题目: Given an integer n, return the number of trailing zeroes in n!. Note: Your solution should be in ...
- Leet Code OJ 206. Reverse Linked List [Difficulty: Easy]
题目: Reverse a singly linked list. Hint: A linked list can be reversed either iteratively or recursiv ...
- Leet Code OJ 38. Count and Say [Difficulty: Easy]
题目: The count-and-say sequence is the sequence of integers beginning as follows: 1, 11, 21, 1211, 11 ...
- Leet Code OJ 226. Invert Binary Tree [Difficulty: Easy]
题目: Invert a binary tree. 4 / \ 2 7 / \ / \ 1 3 6 9 to 4 / \ 7 2 / \ / \ 9 6 3 1 思路分析: 题意是将二叉树所有左右子数 ...
最新文章
- 那些在学习iOS开发前就应该知道的事(part 1)
- queuetimer,如何使用CreateTimerQueueTimer建立在C#中高分辨率计时器?
- 我看Chrome超越IE的意义
- 矢量合成和分解的法则_重点解析丨抛体运动 之 运动的合成与分解
- 怎么判断网络回路_电源纹波要怎么测?
- 程序员诗词大赛开始了,你看过吗?
- UE4学习-材质快捷键及材质帮助手册
- python对文件的_python 对文件操作
- 小白该如何学习Linux操作系统(1)
- HDU 1285:确定比赛名次(拓扑排序)
- 3分钟tips:泛函中,什么是开映像定理?
- EXCHANGE服务器一些常用的邮件限制方法笔记
- maven工程下管理module发布到SVN注意
- 火狐浏览器书签不同步问题
- opporeno怎么刷鸿蒙系统,opporeno老是提示更新系统
- Vue单文件不兼容IE解决方法
- 多线程、并发/并行、自定义线程类、线程安全、守护线程、定时器、线程状态、线程池
- 一周速递|OpenAI:AI通过看视频学会玩《我的世界》,人类第一块量子尺度电路发布
- webpack - 基础打包实现
- matlab dae,matlab解DAE遇到的问题
热门文章
- windows mysql5.719_Window Mysql 5.7.18安装
- 最强解析面试题:无环链表相交
- 如何找到适合你自己的工作?
- 曾仕强-中国式管理语录
- 小程序通用转译框架娜娜奇1.0.4发布
- Ruby操纵外部数据(四)
- 帕金森的病因是什么?
- Android的ams功能,AndroidWMS与AMS
- hibernate的方言是什么??
- 车牌识别的matlab程序(程序_讲解_模板),车牌识别的matlab程序(程序,讲解,模板) - 图文...