随笔分类 -  sliding window

904. Fruit Into Baskets
摘要:In a row of trees, the i-th tree produces fruit with type tree[i]. You start at any tree of your choice, then repeatedly perform the following steps: 1. Add one piece of fruit from this tree to your ... 阅读全文

posted @ 2018-11-08 17:01 猪猪🐷

187. Repeated DNA Sequences
摘要:All DNA is composed of a series of nucleotides abbreviated as A, C, G, and T, for example: "ACGAATTCCG". When studying DNA, it is sometimes useful to identify repeated sequences within the DNA. Write... 阅读全文

posted @ 2018-11-08 02:17 猪猪🐷

3 Longest Substring Without Repeating Characters
摘要:Given a string, find the length of the longest substring without repeating characters. Example 1: Input: "abcabcbb" Output: 3 Explanation: The answer is "abc", with the length of 3. Example 2: Inpu... 阅读全文

posted @ 2018-11-08 02:12 猪猪🐷

487. Max Consecutive Ones II
摘要:Given a binary array, find the maximum number of consecutive 1s in this array if you can flip at most one 0. Example 1: Input: [1,0,1,1,0] Output: 4 Explanation: Flip the first zero will get the the... 阅读全文

posted @ 2018-11-08 02:09 猪猪🐷

424. Longest Repeating Character Replacement
摘要:Given a string that consists of only uppercase English letters, you can replace any letter in the string with another letter at most k times. Find the length of a longest substring containing all rep... 阅读全文

posted @ 2018-11-08 01:42 猪猪🐷

567. Permutation in String (return true if s2 contains the permutation of s1.)
摘要:Given two strings s1 and s2, write a function to return true if s2 contains the permutation of s1. In other words, one of the first string's permutati 阅读全文

posted @ 2018-08-28 20:46 猪猪🐷

209. 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 阅读全文

posted @ 2018-08-11 05:15 猪猪🐷

159. Longest Substring with At Most Two Distinct Characters
摘要:Given a string s , find the length of the longest substring t that contains at most 2 distinct characters. Example 1: Example 2: 阅读全文

posted @ 2018-08-11 04:55 猪猪🐷

395 Longest Substring with At Least K Repeating Characters
摘要:Find the length of the longest substring T of a given string (consists of lowercase letters only) such that every character in T appears no less than  阅读全文

posted @ 2018-08-10 15:07 猪猪🐷

346. Moving Average from Data Stream
摘要:the next() func takes in an integer, First check if the queue size() == maxSize if it’s the same, then we poll the top, which is the one we added firs 阅读全文

posted @ 2018-08-10 14:38 猪猪🐷

239. Sliding Window Maximum/ min
摘要:239. Sliding Window Maximum/ min https://www.youtube.com/watch?v=2SXqBsTR6a8 https://www.youtube.com/watch?v=G70qltIBF40 过例子, 写自己的 思路, 然后写自己的代码 class 阅读全文

posted @ 2018-08-09 18:16 猪猪🐷

340. Longest Substring with At Most K Distinct Characters
摘要:Given a string, find the length of the longest substring T that contains at most k distinct characters. Example 1: Input: s = "eceba", k = 2 Output: 3 阅读全文

posted @ 2018-08-09 17:44 猪猪🐷

438. Find All Anagrams in a String (find all the start indices of p's anagrams in s.)
摘要: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 @ 2018-08-09 17:29 猪猪🐷

76 - Minimum Window Substring
摘要: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: Note: If there i 阅读全文

posted @ 2018-08-09 17:28 猪猪🐷

209. 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 阅读全文

posted @ 2018-07-18 09:03 猪猪🐷

导航