leetcode第一刷_Merge Sorted Array
水题,只是思想还是实用的。
当然能够新建出一个数组。比較着拷贝过去。可是没有必要啊亲。想想为什么用源数组会麻烦,由于确定了前面的数。为了后面的数字不被覆盖,要依次往后移,转念一想,先确定后面的数字。就不用操心会覆盖的问题了。像不像杨辉三角形中仅仅要求O(N)空间时的思想,好多好多样例。
class Solution {
public:
void merge(int A[], int m, int B[], int n) {
int i=m-1, j = n-1, k = m+n-1;
while(i>=0&&j>=0){
if(A[i]<B[j]){
A[k] = B[j];
--j;
}else{
A[k] = A[i];
--i;
}
--k;
}
while(j>=0){
A[k] = B[j];
--k;
--j;
}
}
};
leetcode第一刷_Merge Sorted Array的更多相关文章
- leetcode第一刷_Convert Sorted Array to Binary Search Tree
晕.竟然另一样的一道题.换成sorted array的话.找到中间位置更加方便了. TreeNode *sortTree(vector<int> &num, int start, ...
- leetcode第一刷_Merge Intervals
看到这个题我就伤心啊,去微软面试的时候,第一个面试官让我做的题目就是实现集合的交操作,这个集合中的元素就像这里的interval一样.是一段一段的.当时写的那叫一个慘不忍睹.最后果然被拒掉了. .好好 ...
- leetcode第一刷_Convert Sorted List to Binary Search Tree
好,二叉搜索树粉末登场,有关他的问题有这么几个,给你一个n,如何求全部的n个节点的二叉搜索树个数?能不能把全部的这些二叉搜索树打印出来? 这道题倒不用考虑这么多,直接转即可了,我用的思想是分治,每次找 ...
- LeetCode: Search in Rotated Sorted Array II 解题报告
Search in Rotated Sorted Array II Follow up for "LeetCode: Search in Rotated Sorted Array 解题报告& ...
- LeetCode:Search in Rotated Sorted Array I II
LeetCode:Search in Rotated Sorted Array Suppose a sorted array is rotated at some pivot unknown to y ...
- LeetCode:Remove Duplicates from Sorted Array I II
LeetCode:Remove Duplicates from Sorted Array Given a sorted array, remove the duplicates in place su ...
- [LeetCode] Remove Duplicates from Sorted Array 有序数组中去除重复项
Given a sorted array, remove the duplicates in place such that each element appear only once and ret ...
- 【LeetCode】108. Convert Sorted Array to Binary Search Tree 解题报告 (Java & Python)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 Java解法 Python解法 日期 题目地址:ht ...
- 【LeetCode】88. Merge Sorted Array 解题报告(Java & Python)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 新建数组 日期 题目地址:https://leetc ...
随机推荐
- OCP读书笔记(8) - 监控和调优RMAN
监视RMAN作业 1. 创建rman备份: RMAN> run { allocate channel ch1 type disk; allocate channel ch2 type disk; ...
- java.lang.IllegalAccessError: class javax.activation.SecuritySupport12 cannot access its superclass
最近加入新的项目组,eclipse + tomcat7 + spring +ibatis + restful 遇到了这样的问题, 说是不能访问父类,我一开始以为是版本的原因,但是久经更改,错误依然,实 ...
- Nagios监控系统的安装
环境:centOS 6.5 X86 64位 nagios-4.08 步骤: 1. 最小化安装系统 2. 修改安全特性 关闭SELINUX SELINUX=disabled 清除iptabl ...
- Android设备管理器漏洞2--禁止用户取消激活设备管理器
2013年6月,俄罗斯安全厂商卡巴斯基发现了史上最强手机木马-Obad.A.该木马利用了一个未知的Android设备管理器漏洞(ANDROID-9067882),已激活设备管理器权限的手机木马利用该漏 ...
- JQuery插件datatables相关api
学习可参考:http://www.guoxk.com/node/jquery-datatables http://yuemeiqing2008-163-com.iteye.com/blog/20069 ...
- filezilla安装
[alexus@wcmisdlin02 bin]$ ./filezilla ./filezilla: /lib64/libstdc++.so.6: version `CXXABI_1.3.8' not ...
- RVDS 3.1 下载地址及破解方法
RealView Development Suite 3.1 RVDS 3.1下载地址:https://silver.arm.com/download/Development_Tools/RVDS/ ...
- The Django template language 阅读批注
The Django template language About this document This document explains the language syntax of the D ...
- java中浮点数的比较(double, float)(转)
问题的提出:如果我们编译运行下面这个程序会看到什么? public static void main(String args[]){ System.out.println(0.05+0.01); Sy ...
- MySQLdb 连接Mysql 数据库出错解决
#coding=utf-8 import MySQLdb if __name__ == "__main__": db = MySQLdb.connect(host=<sp ...