
Leetcode
qq_41837911
这个作者很懒,什么都没留下…
展开
-
Leetcode 35题 搜索插入位置
给定一个排序数组和一个目标值,在数组中找到目标值,并返回其索引。如果目标值不存在于数组中,返回它将会被按顺序插入的位置。你可以假设数组中无重复元素。示例 1: 输入: [1,3,5,6], 5 输出: 2 示例 2: 输入: [1,3,5,6], 7 输出: 4思路1:给定的数组是有序的,先判断目标是是否比数组的第一个元素小(返回下标0)或比最后一个元素大(返回数组长度),然后通...原创 2018-10-18 10:20:02 · 403 阅读 · 0 评论 -
Leetcode 53. 最大子序和
给定一个整数数组 nums ,找到一个具有最大和的连续子数组(子数组最少包含一个元素),返回其最大和。示例:输入: [-2,1,-3,4,-1,2,1,-5,4],输出: 6解释: 连续子数组 [4,-1,2,1] 的和最大,为 6。进阶: 如果你已经实现复杂度为 O(n) 的解法,尝试使用更为精妙的分治法求解。思路1:动态规划算法——时间复杂度为O(N)求解思路:用s...原创 2018-10-18 12:02:18 · 121 阅读 · 0 评论 -
Leetcode 66. 加一
给定一个由整数组成的非空数组所表示的非负整数,在该数的基础上加一。最高位数字存放在数组的首位, 数组中每个元素只存储一个数字。你可以假设除了整数 0 之外,这个整数不会以零开头。示例 1:输入: [1,2,3]输出: [1,2,4]解释: 输入数组表示数字 123。示例 2:输入: [9,9,9]输出: [1,0,0,0]解释: 输入数组表示数字 999。...原创 2018-10-18 15:38:55 · 140 阅读 · 0 评论 -
Leetcode 283 Move Zeros
Given an array nums, write a function to move all 0's to the end of it while maintaining the relative order of the non-zero elements.Example:Input: [0,1,0,3,12]Output: [1,3,12,0,0]Note:You m...原创 2018-10-22 21:26:44 · 159 阅读 · 0 评论 -
Leetcode 88. Merge Sorted Array
Given two sorted integer arrays nums1 and nums2, merge nums2 into nums1 as one sorted array.Note:The number of elements initialized in nums1 andnums2 are m and n respectively. You may assume that...原创 2018-10-23 16:14:16 · 163 阅读 · 0 评论