
一、数组问题
司曹龙学编程
多学习 多努力 好好学编程
展开
-
leetcode 283 move zero
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-08-01 15:27:13 · 215 阅读 · 0 评论 -
leetcode 76. 最小覆盖子串 (数组中的问题 滑动窗口和查找表的组合)
给定一个字符串 S 和一个字符串 T,请在 S 中找出包含 T 所有字母的最小子串。示例:输入: S = "ADOBECODEBANC", T = "ABC"输出: "BANC"说明:如果 S 中不存这样的子串,则返回空字符串 ""。 如果 S 中存在这样的子串,我们保证它是唯一的答案。思路:首先处理特殊情况 字符串为空 已经s串小于t串的长度的情况; 再者将t中的...原创 2018-08-03 09:55:08 · 593 阅读 · 0 评论 -
leetcode 438Find All Anagrams in a String 大概就是寻找异位词;
Given a string s and a non-empty string p, find all the start indices of p's anagrams in s.Strings consists of lowercase English letters only and the length of both strings s and p will not be large...原创 2018-08-02 15:41:18 · 168 阅读 · 0 评论 -
leetcode 3 Longest Substring Without Repeating Characters
Given a string, find the length of the longest substring without repeating characters.Examples:Given "abcabcbb", the answer is "abc", which the length is 3.Given "bbbbb", the answer is "b", with...原创 2018-08-02 15:18:28 · 107 阅读 · 0 评论 -
leetcode209. Minimum Size Subarray Sum
Given an array of n positive integers and a positive integer s, find the minimal length of a contiguous subarray of which the sum ≥ s. If there isn't one, return 0 instead.Example: Input: s = 7, ...原创 2018-08-02 14:33:05 · 124 阅读 · 0 评论 -
leetcode 11. Container With Most Water
Given n non-negative integers a1, a2, ..., an , where each represents a point at coordinate (i, ai). n vertical lines are drawn such that the two endpoints of line i is at (i, ai) and (i, 0). Find two...原创 2018-08-02 13:45:33 · 105 阅读 · 0 评论 -
leetcode 345. Reverse Vowels of a String
Write a function that takes a string as input and reverse only the vowels of a string.Example 1:Given s = "hello", return "holle".Example 2:Given s = "leetcode", return "leotcede".Note:The vo...原创 2018-08-02 11:18:52 · 176 阅读 · 0 评论 -
leetcode 125 Valid Palindrome
Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignoring cases.Note: For the purpose of this problem, we define empty string as valid palindrome.Examp...原创 2018-08-02 00:49:41 · 112 阅读 · 0 评论 -
leetcode 167 Two sum II inout array is sorted
Given an array of integers that is already sorted in ascending order, find two numbers such that they add up to a specific target number.The function twoSum should return indices of the two numbers ...原创 2018-08-01 21:54:52 · 116 阅读 · 0 评论 -
leetcode 215 寻找数组中的第k大的值;
Find the kth largest element in an unsorted array. Note that it is the kth largest element in the sorted order, not the kth distinct element.Example 1:Input: [3,2,1,5,6,4] and k = 2Output: 5E...原创 2018-08-01 21:35:47 · 728 阅读 · 0 评论 -
leetcode 75 sort colors 数组问题
Given an array with n objects colored red, white or blue, sort them in-place so that objects of the same color are adjacent, with the colors in the order red, white and blue.Here, we will use the in...原创 2018-08-01 19:13:19 · 143 阅读 · 0 评论 -
leetcode 26 从排序数组中删除重复项
https://leetcode.com/problems/remove-duplicates-from-sorted-array/description/Given a sorted array nums, remove the duplicates in-place such that each element appear only once and return the new len...原创 2018-08-01 17:06:50 · 434 阅读 · 0 评论 -
leetcode 27 Remove Element
给定一个数组 nums 和一个值 val,你需要原地移除所有数值等于 val 的元素,返回移除后数组的新长度。不要使用额外的数组空间,你必须在原地修改输入数组并在使用 O(1) 额外空间的条件下完成。元素的顺序可以改变。你不需要考虑数组中超出新长度后面的元素。示例 1:给定 nums = [3,2,2,3], val = 3,函数应该返回新的长度 2, 并且 nums 中的前...原创 2018-08-01 16:03:48 · 107 阅读 · 0 评论 -
(三)剑指offer40 和为S的连续正数序列(滑动窗口)
思路 就是求几个连续数组的和等于sum;设置变量 left=1;right=-1;滑动窗口的初始化为不可能取得的值;int cur=0; 循环的条件while(left<sum); if(cur<sum&&right+1<sum) cur+=++right; else cur-=left++; if(cur==sum) temp.push_bac...原创 2018-08-31 17:05:27 · 161 阅读 · 0 评论