随笔分类 -  Two Pointers

摘要:Given an array nums 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 阅读全文
posted @ 2020-10-25 09:57 苗妙苗 阅读(251) 评论(0) 推荐(0)
摘要:Given an array nums, there is a sliding window of size k which is moving from the very left of the array to the very right. You can only see the k num 阅读全文
posted @ 2020-09-14 21:28 苗妙苗 阅读(92) 评论(0) 推荐(0)
摘要: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 阅读全文
posted @ 2020-08-02 11:07 苗妙苗 阅读(147) 评论(0) 推荐(0)
摘要: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 阅读全文
posted @ 2020-08-01 10:24 苗妙苗 阅读(130) 评论(0) 推荐(0)
摘要:Given a string s , find the length of the longest substring t that contains at most 2 distinct characters. Example 1: Input: "eceba" Output: 3 Explana 阅读全文
posted @ 2020-07-31 23:22 苗妙苗 阅读(123) 评论(0) 推荐(0)
摘要:Given a string, find the length of the longest substring without repeating characters. Example 1: Input: "abcabcbb" Output: 3 Explanation: The answer 阅读全文
posted @ 2020-07-31 11:19 苗妙苗 阅读(135) 评论(0) 推荐(0)
摘要:Given a string S and a string T, find the minimum window in S which will contain all the characters in T in complexity O(n). Example: Input: S = "ADOB 阅读全文
posted @ 2020-07-30 10:34 苗妙苗 阅读(122) 评论(0) 推荐(0)
摘要:Given a string S and a string T, find the minimum window in S which will contain all the characters in T in complexity O(n). Example: Input: S = "ADOB 阅读全文
posted @ 2020-06-08 21:43 苗妙苗 阅读(157) 评论(0) 推荐(0)
摘要: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 阅读全文
posted @ 2020-06-08 10:30 苗妙苗 阅读(150) 评论(0) 推荐(0)
摘要:Given a string, find the length of the longest substring without repeating characters. Example 1: Input: "abcabcbb" Output: 3 Explanation: The answer 阅读全文
posted @ 2020-06-07 05:29 苗妙苗 阅读(73) 评论(0) 推荐(0)
摘要:[抄题]: Given a string which contains only letters. Sort it by lower case first and upper case second. Example Example 1: Input: "abAcD" Output: "acbAD" 阅读全文
posted @ 2020-05-13 10:39 苗妙苗 阅读(184) 评论(0) 推荐(0)
摘要:[抄题]: Given an array of n integers nums and a target, find the number of index triplets i, j, k with 0 <= i < j < k < n that satisfy the condition num 阅读全文
posted @ 2018-08-12 21:55 苗妙苗 阅读(156) 评论(0) 推荐(0)
摘要:[抄题]: Given a sorted array of integers nums and integer values a, b and c. Apply a quadratic function of the form f(x) = ax2 + bx + c to each element  阅读全文
posted @ 2018-08-11 23:30 苗妙苗 阅读(170) 评论(0) 推荐(0)
摘要:[抄题]: A string S of lowercase letters is given. We want to partition this string into as many parts as possible so that each letter appears in at most 阅读全文
posted @ 2018-08-03 21:59 苗妙苗 阅读(234) 评论(0) 推荐(0)
摘要:[抄题]: Given an array nums containing n + 1 integers where each integer is between 1 and n (inclusive), prove that at least one duplicate number must e 阅读全文
posted @ 2018-08-01 21:45 苗妙苗 阅读(148) 评论(0) 推荐(0)
摘要:[抄题]: Given a list of words and two words word1 and word2, return the shortest distance between these two words in the list. word1 and word2 may be th 阅读全文
posted @ 2018-07-28 17:31 苗妙苗 阅读(159) 评论(0) 推荐(0)
摘要:Sum类的题目一般这样: input: nums[], target output: satisfied arrays/ lists/ number 拿到题目,首先分析: 1. 是几个数的sum 2. sum是要求等于target还是小于还是大于还是closest 3. 返回的是原数组下标还是其他 阅读全文
posted @ 2018-07-12 17:32 苗妙苗 阅读(167) 评论(0) 推荐(0)
摘要:[抄题]: Assume you are an awesome parent and want to give your children some cookies. But, you should give each child at most one cookie. Each child i h 阅读全文
posted @ 2018-04-30 15:36 苗妙苗 阅读(148) 评论(0) 推荐(0)
摘要:[抄题]: A strobogrammatic number is a number that looks the same when rotated 180 degrees (looked at upside down). Write a function to determine if a nu 阅读全文
posted @ 2018-04-27 11:07 苗妙苗 阅读(218) 评论(0) 推荐(0)
摘要:[抄题]: Given a non-empty string s, you may delete at most one character. Judge whether you can make it a palindrome. Example 1: Example 2: [暴力解法]: 时间分析 阅读全文
posted @ 2018-03-20 21:10 苗妙苗 阅读(206) 评论(0) 推荐(0)