LeetCode编程练习
来源:互联网 发布:什么是php网站 编辑:程序博客网 时间:2024/06/16 10:43
题目:
Given two sorted integer arraysnums1 andnums2, mergenums2 intonums1 as one sorted array.
Note:
You may assume thatnums1 has enough space (size that is greater or equal tom +n) to hold additional elements fromnums2. The number of elements initialized innums1 andnums2 arem andn respectively.
给定两个排序整数数组nums1和nums2,将nums2合并为nums1作为一个排序数组。假设nums1有足够的空间(大于等于m+n),以容纳来自nums2的额外元素nums1和nums2中初始化的元素分别为m,n。
思路:
定义一个新的大小为m+n的数组,用来装载合并的数组,判断定义的遍历两个数组的变量的大小,进行赋值。输出错误。
查看解决方案,先定义了遍历数组的变量,然后循环比较大小,最后判断是否已经遍历完,然后将多出来的数添加到数组中。
还可以简化一下程序,用到判断运算符“?:”
与Linked List中的Merge Two Sorted Lists类似。
阅读全文
0 0
- LeetCode编程练习
- LeetCode编程练习
- LeetCode编程练习
- LeetCode编程练习
- LeetCode编程练习
- LeetCode编程练习
- LeetCode 编程练习
- LeetCode编程练习
- LeetCode编程练习
- LeetCode编程练习
- LeetCode编程练习
- LeetCode编程练习
- LeetCode编程练习
- LeetCode编程练习
- LeetCode编程练习
- LeetCode编程练习
- LeetCode编程练习
- LeetCode编程练习
- 官方自带的Toast
- RecyclerView源码分析
- AngularJS中$http服务
- C++模板(二)-类模板
- 【安全牛学习笔记】WPS及其他工具
- LeetCode编程练习
- 452. Minimum Number of Arrows to Burst Balloons(greedy)
- 51nod 1130 N的阶乘的长度 V2(斯特林近似)
- 怎么导入github上的maven项目到eclipse中
- gym101431D(传说中的构造(呸))
- cocos2d-x(lua)的安装和运行helloworld(一)
- LeetCode编程练习
- 什么是CDN?CDN有什么用处?
- error: conversion from 'std::_List_const_iterator<_Mylist>' to non-scalar type 'std::_List_iterator<