<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Leetcode on 111qqz's blog</title><link>https://111qqz.com/en/tags/leetcode/</link><description>Recent content in Leetcode on 111qqz's blog</description><generator>Hugo -- gohugo.io</generator><language>en</language><copyright>© 2015-2026 111qqz</copyright><lastBuildDate>Sun, 03 Jan 2021 16:54:57 +0800</lastBuildDate><atom:link href="https://111qqz.com/en/tags/leetcode/index.xml" rel="self" type="application/rss+xml"/><item><title>2020年终总结</title><link>https://111qqz.com/en/post/%E7%94%9F%E6%B4%BB/2021-01-03-my-2020/</link><pubDate>Sun, 03 Jan 2021 16:54:57 +0800</pubDate><guid>https://111qqz.com/en/post/%E7%94%9F%E6%B4%BB/2021-01-03-my-2020/</guid><description>&lt;p&gt;本来不知道写什么所以不打算写了，不过后来觉得可以把今年做的一些重大的决定写出来，把当时的分析和想法记录下来。这样若干年后再回看，就能找到，是哪些明智或愚蠢的决定，对人生产生了巨大的影响。&lt;/p&gt;</description></item><item><title>leetcode162. Find Peak Element (O(lgn)复杂度寻找峰值)</title><link>https://111qqz.com/en/post/acm-icpc/2017/2017-04-14-leetcode-162/</link><pubDate>Fri, 14 Apr 2017 12:25:16 +0000</pubDate><guid>https://111qqz.com/en/post/acm-icpc/2017/2017-04-14-leetcode-162/</guid><description>&lt;p&gt;A peak element is an element that is greater than its neighbors.&lt;/p&gt;
&lt;p&gt;Given an input array where &lt;code&gt;num[i] ≠ num[i+1]&lt;/code&gt;, find a peak element and return its index.&lt;/p&gt;
&lt;p&gt;The array may contain multiple peaks, in that case return the index to any one of the peaks is fine.&lt;/p&gt;</description></item><item><title>leetcode 152. Maximum Product Subarray (最大连续子序列乘积，dp)</title><link>https://111qqz.com/en/post/acm-icpc/2017/2017-04-14-leetcode-152-maximum-product-subarray/</link><pubDate>Fri, 14 Apr 2017 11:33:30 +0000</pubDate><guid>https://111qqz.com/en/post/acm-icpc/2017/2017-04-14-leetcode-152-maximum-product-subarray/</guid><description>&lt;p&gt;Find the contiguous subarray within an array (containing at least one number) which has the largest product.&lt;/p&gt;
&lt;p&gt;For example, given the array &lt;code&gt;[2,3,-2,4]&lt;/code&gt;,
the contiguous subarray &lt;code&gt;[2,3]&lt;/code&gt; has the largest product = &lt;code&gt;6&lt;/code&gt;.&lt;/p&gt;</description></item><item><title>leetcode 228. Summary Ranges</title><link>https://111qqz.com/en/post/acm-icpc/2017/2017-04-14-leetcode-228-summary-ranges/</link><pubDate>Fri, 14 Apr 2017 10:51:39 +0000</pubDate><guid>https://111qqz.com/en/post/acm-icpc/2017/2017-04-14-leetcode-228-summary-ranges/</guid><description>&lt;p&gt;Given a sorted integer array without duplicates, return the summary of its ranges.&lt;/p&gt;
&lt;p&gt;For example, given &lt;code&gt;[0,1,2,4,5,7]&lt;/code&gt;, return &lt;code&gt;[&amp;quot;0-&amp;gt;2&amp;quot;,&amp;quot;4-&amp;gt;5&amp;quot;,&amp;quot;7&amp;quot;].&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;题意：把连续的数连续表示&lt;/p&gt;</description></item><item><title>leetcode 209. Minimum Size Subarray Sum (尺取法)</title><link>https://111qqz.com/en/post/acm-icpc/2017/2017-04-13-leetcode-209-minimum-size-subarray-sum/</link><pubDate>Thu, 13 Apr 2017 13:50:02 +0000</pubDate><guid>https://111qqz.com/en/post/acm-icpc/2017/2017-04-13-leetcode-209-minimum-size-subarray-sum/</guid><description>&lt;p&gt;Given an array of &lt;strong&gt;n&lt;/strong&gt; positive integers and a positive integer &lt;strong&gt;s&lt;/strong&gt;, find the minimal length of a &lt;strong&gt;contiguous&lt;/strong&gt; subarray of which the sum ≥ &lt;strong&gt;s&lt;/strong&gt;. If there isn&amp;rsquo;t one, return 0 instead.&lt;/p&gt;</description></item><item><title>leetcode 229. Majority Element II （O(1)空间找出现次数大于n/3的元素）</title><link>https://111qqz.com/en/post/acm-icpc/2017/2017-04-13-leetcode-229-majority-element-ii/</link><pubDate>Thu, 13 Apr 2017 12:41:33 +0000</pubDate><guid>https://111qqz.com/en/post/acm-icpc/2017/2017-04-13-leetcode-229-majority-element-ii/</guid><description>&lt;p&gt;Given an integer array of size &lt;em&gt;n&lt;/em&gt;, find all elements that appear more than &lt;code&gt;⌊ n/3 ⌋&lt;/code&gt; times. The algorithm should run in linear time and in O(1) space.&lt;/p&gt;
&lt;p&gt;题意：给你n个数，要求找出出现此处大于n/3的。。。&lt;/p&gt;</description></item><item><title>leetcode 75. Sort Colors</title><link>https://111qqz.com/en/post/acm-icpc/2017/2017-04-13-leetcode-75-sort-colors/</link><pubDate>Thu, 13 Apr 2017 12:02:02 +0000</pubDate><guid>https://111qqz.com/en/post/acm-icpc/2017/2017-04-13-leetcode-75-sort-colors/</guid><description>&lt;p&gt;Given an array with &lt;em&gt;n&lt;/em&gt; objects colored red, white or blue, sort them so that objects of the same color are adjacent, with the colors in the order red, white and blue.&lt;/p&gt;</description></item><item><title>leetcode 11. Container With Most Water (two pointer)</title><link>https://111qqz.com/en/post/acm-icpc/2017/2017-04-13-leetcode-11-container-with-most-water-two-pointer/</link><pubDate>Thu, 13 Apr 2017 10:13:01 +0000</pubDate><guid>https://111qqz.com/en/post/acm-icpc/2017/2017-04-13-leetcode-11-container-with-most-water-two-pointer/</guid><description>&lt;p&gt;Given &lt;em&gt;n&lt;/em&gt; non-negative integers &lt;em&gt;a1&lt;/em&gt;, &lt;em&gt;a2&lt;/em&gt;, &amp;hellip;, &lt;em&gt;an&lt;/em&gt;, where each represents a point at coordinate (&lt;em&gt;i&lt;/em&gt;, &lt;em&gt;ai&lt;/em&gt;). &lt;em&gt;n&lt;/em&gt; vertical lines are drawn such that the two endpoints of line &lt;em&gt;i&lt;/em&gt; is at (&lt;em&gt;i&lt;/em&gt;, &lt;em&gt;ai&lt;/em&gt;) and (&lt;em&gt;i&lt;/em&gt;, 0). Find two lines, which together with x-axis forms a container, such that the container contains the most water.&lt;/p&gt;</description></item><item><title>leetcode 16. 3Sum Closest (k-sum问题，two pointer)</title><link>https://111qqz.com/en/post/acm-icpc/2017/2017-04-13-leetcode-16-3sum-closest/</link><pubDate>Thu, 13 Apr 2017 09:45:45 +0000</pubDate><guid>https://111qqz.com/en/post/acm-icpc/2017/2017-04-13-leetcode-16-3sum-closest/</guid><description>&lt;p&gt;Given an array &lt;em&gt;S&lt;/em&gt; of &lt;em&gt;n&lt;/em&gt; integers, find three integers in &lt;em&gt;S&lt;/em&gt; such that the sum is closest to a given number, target. Return the sum of the three integers. You may assume that each input would have exactly one solution.&lt;/p&gt;</description></item><item><title>leetcode 18. 4Sum (k-sum问题，two pointer)</title><link>https://111qqz.com/en/post/acm-icpc/2017/2017-04-13-leetcode-18-4sum/</link><pubDate>Thu, 13 Apr 2017 09:34:15 +0000</pubDate><guid>https://111qqz.com/en/post/acm-icpc/2017/2017-04-13-leetcode-18-4sum/</guid><description>&lt;p&gt;Given an array &lt;em&gt;S&lt;/em&gt; of &lt;em&gt;n&lt;/em&gt; integers, are there elements &lt;em&gt;a&lt;/em&gt;, &lt;em&gt;b&lt;/em&gt;, &lt;em&gt;c&lt;/em&gt;, and &lt;em&gt;d&lt;/em&gt; in &lt;em&gt;S&lt;/em&gt; such that &lt;em&gt;a&lt;/em&gt; + &lt;em&gt;b&lt;/em&gt; + &lt;em&gt;c&lt;/em&gt; + &lt;em&gt;d&lt;/em&gt; = target? Find all unique quadruplets in the array which gives the sum of target.&lt;/p&gt;</description></item><item><title>leetcode 15. 3Sum (k-sum问题，two pointer)</title><link>https://111qqz.com/en/post/acm-icpc/2017/2017-04-13-leetcode-15-3sum/</link><pubDate>Thu, 13 Apr 2017 08:21:52 +0000</pubDate><guid>https://111qqz.com/en/post/acm-icpc/2017/2017-04-13-leetcode-15-3sum/</guid><description>&lt;p&gt;Given an array &lt;em&gt;S&lt;/em&gt; of &lt;em&gt;n&lt;/em&gt; integers, are there elements &lt;em&gt;a&lt;/em&gt;, &lt;em&gt;b&lt;/em&gt;, &lt;em&gt;c&lt;/em&gt; in &lt;em&gt;S&lt;/em&gt; such that &lt;em&gt;a&lt;/em&gt; + &lt;em&gt;b&lt;/em&gt; + &lt;em&gt;c&lt;/em&gt; = 0? Find all unique triplets in the array which gives the sum of zero.&lt;/p&gt;</description></item><item><title>leetcode 216. Combination Sum III Add to List (枚举子集，限定集合大小，和为定值）</title><link>https://111qqz.com/en/post/acm-icpc/2017/2017-04-13-leetcode-216-combination-sum-iii-add-to-list/</link><pubDate>Thu, 13 Apr 2017 07:55:09 +0000</pubDate><guid>https://111qqz.com/en/post/acm-icpc/2017/2017-04-13-leetcode-216-combination-sum-iii-add-to-list/</guid><description>&lt;p&gt;Find all possible combinations of &lt;em&gt;&lt;strong&gt;k&lt;/strong&gt;&lt;/em&gt; numbers that add up to a number &lt;em&gt;&lt;strong&gt;n&lt;/strong&gt;&lt;/em&gt;, given that only numbers from 1 to 9 can be used and each combination should be a unique set of numbers.&lt;/p&gt;</description></item><item><title>leetcode 60. Permutation Sequence (求第k个排列)</title><link>https://111qqz.com/en/post/acm-icpc/2017/2017-04-13-leetcode-60-permutation-sequence/</link><pubDate>Thu, 13 Apr 2017 07:24:41 +0000</pubDate><guid>https://111qqz.com/en/post/acm-icpc/2017/2017-04-13-leetcode-60-permutation-sequence/</guid><description>&lt;p&gt;The set &lt;code&gt;[1,2,3,…,_n_]&lt;/code&gt; contains a total of &lt;em&gt;n&lt;/em&gt;! unique permutations.&lt;/p&gt;
&lt;p&gt;By listing and labeling all of the permutations in order,
We get the following sequence (ie, for &lt;em&gt;n&lt;/em&gt; = 3):&lt;/p&gt;</description></item><item><title>leetcode 47. Permutations II (生成全排列，有重复元素)</title><link>https://111qqz.com/en/post/acm-icpc/2017/2017-04-13-leetcode-47-permutations-ii/</link><pubDate>Thu, 13 Apr 2017 07:14:03 +0000</pubDate><guid>https://111qqz.com/en/post/acm-icpc/2017/2017-04-13-leetcode-47-permutations-ii/</guid><description>&lt;p&gt;Given a collection of numbers that might contain duplicates, return all possible unique permutations.__&lt;/p&gt;
&lt;p&gt;思路：和&lt;a href="https://111qqz.com/en/post/acm-icpc/2017/2017-04-13-leetcode-46-permutations/" &gt;leet code 46&lt;/a&gt; 类似，最后用set去个重即可。。&lt;/p&gt;</description></item><item><title>leetcode 46. Permutations (生成全排列，无重复元素)</title><link>https://111qqz.com/en/post/acm-icpc/2017/2017-04-13-leetcode-46-permutations/</link><pubDate>Thu, 13 Apr 2017 06:59:43 +0000</pubDate><guid>https://111qqz.com/en/post/acm-icpc/2017/2017-04-13-leetcode-46-permutations/</guid><description>&lt;p&gt;Given a collection of &lt;strong&gt;distinct&lt;/strong&gt; numbers, return all possible permutations.&lt;/p&gt;
&lt;p&gt;思路：调用n-1次 &lt;a href="https://111qqz.com/en/post/acm-icpc/2017/2017-04-13-leetcode-31-next-permutation-in-place/" &gt;leetcode 31 解题报告&lt;/a&gt; 中提到的算法即可。。。&lt;/p&gt;</description></item><item><title>leetcode 31. Next Permutation (in-place 生成下一个全排列)</title><link>https://111qqz.com/en/post/acm-icpc/2017/2017-04-13-leetcode-31-next-permutation-in-place/</link><pubDate>Thu, 13 Apr 2017 06:47:55 +0000</pubDate><guid>https://111qqz.com/en/post/acm-icpc/2017/2017-04-13-leetcode-31-next-permutation-in-place/</guid><description>&lt;p&gt;Implement next permutation, which rearranges numbers into the lexicographically next greater permutation of numbers.&lt;/p&gt;
&lt;p&gt;If such arrangement is not possible, it must rearrange it as the lowest possible order (ie, sorted in ascending order).&lt;/p&gt;</description></item><item><title>leetcode 33. Search in Rotated Sorted Array (无重复数的旋转数组找定值)</title><link>https://111qqz.com/en/post/acm-icpc/2017/2017-04-13-leetcode-33-search-in-rotated-sorted-array/</link><pubDate>Thu, 13 Apr 2017 06:29:37 +0000</pubDate><guid>https://111qqz.com/en/post/acm-icpc/2017/2017-04-13-leetcode-33-search-in-rotated-sorted-array/</guid><description>&lt;p&gt;Suppose an array sorted in ascending order is rotated at some pivot unknown to you beforehand.&lt;/p&gt;
&lt;p&gt;(i.e., &lt;code&gt;0 1 2 4 5 6 7&lt;/code&gt; might become &lt;code&gt;4 5 6 7 0 1 2&lt;/code&gt;).&lt;/p&gt;</description></item><item><title>leetcode 34. Search for a Range (二分，找到一段值为tar的区间)</title><link>https://111qqz.com/en/post/acm-icpc/2017/2017-04-13-leetcode-34-search-for-a-range/</link><pubDate>Thu, 13 Apr 2017 05:34:45 +0000</pubDate><guid>https://111qqz.com/en/post/acm-icpc/2017/2017-04-13-leetcode-34-search-for-a-range/</guid><description>&lt;p&gt;Given an array of integers sorted in ascending order, find the starting and ending position of a given target value.&lt;/p&gt;
&lt;p&gt;Your algorithm&amp;rsquo;s runtime complexity must be in the order of &lt;em&gt;O&lt;/em&gt;(log &lt;em&gt;n&lt;/em&gt;).&lt;/p&gt;</description></item><item><title>leetcode 39. Combination Sum (dfs，求所有的组合，和为定值，每个数可以重复用)</title><link>https://111qqz.com/en/post/acm-icpc/2017/2017-04-13-leetcode-39-combination-sum/</link><pubDate>Thu, 13 Apr 2017 02:47:49 +0000</pubDate><guid>https://111qqz.com/en/post/acm-icpc/2017/2017-04-13-leetcode-39-combination-sum/</guid><description>&lt;p&gt;Given a &lt;strong&gt;set&lt;/strong&gt; of candidate numbers (&lt;strong&gt;&lt;em&gt;C&lt;/em&gt;&lt;/strong&gt;) &lt;strong&gt;(without duplicates)&lt;/strong&gt; and a target number (&lt;strong&gt;&lt;em&gt;T&lt;/em&gt;&lt;/strong&gt;), find all unique combinations in &lt;strong&gt;&lt;em&gt;C&lt;/em&gt;&lt;/strong&gt; where the candidate numbers sums to &lt;strong&gt;&lt;em&gt;T&lt;/em&gt;&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;The &lt;strong&gt;same&lt;/strong&gt; repeated number may be chosen from &lt;strong&gt;&lt;em&gt;C&lt;/em&gt;&lt;/strong&gt; unlimited number of times.&lt;/p&gt;</description></item><item><title>leetcode 40. Combination Sum II (枚举子集，和为定值)</title><link>https://111qqz.com/en/post/acm-icpc/2017/2017-04-12-leetcode-40-combination-ii/</link><pubDate>Wed, 12 Apr 2017 16:23:29 +0000</pubDate><guid>https://111qqz.com/en/post/acm-icpc/2017/2017-04-12-leetcode-40-combination-ii/</guid><description>&lt;pre&gt;&lt;code&gt; * Total Accepted: **106670**
 * Total Submissions: **329718**
 * Difficulty: **Medium**
 * Contributor: **LeetCode**
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Given a collection of candidate numbers (&lt;strong&gt;&lt;em&gt;C&lt;/em&gt;&lt;/strong&gt;) and a target number (&lt;strong&gt;&lt;em&gt;T&lt;/em&gt;&lt;/strong&gt;), find all unique combinations in &lt;strong&gt;&lt;em&gt;C&lt;/em&gt;&lt;/strong&gt; where the candidate numbers sums to &lt;strong&gt;&lt;em&gt;T&lt;/em&gt;&lt;/strong&gt;.&lt;/p&gt;</description></item><item><title>leetcode 495. Teemo Attacking</title><link>https://111qqz.com/en/post/acm-icpc/2017/2017-04-12-leetcode-495-teemo-attacking/</link><pubDate>Wed, 12 Apr 2017 16:00:57 +0000</pubDate><guid>https://111qqz.com/en/post/acm-icpc/2017/2017-04-12-leetcode-495-teemo-attacking/</guid><description>&lt;p&gt;In LLP world, there is a hero called Teemo and his attacking can make his enemy Ashe be in poisoned condition. Now, given the Teemo&amp;rsquo;s attacking &lt;strong&gt;ascending&lt;/strong&gt; time series towards Ashe and the poisoning time duration per Teemo&amp;rsquo;s attacking, you need to output the total time that Ashe is in poisoned condition.&lt;/p&gt;</description></item><item><title>leetcode 442. Find All Duplicates in an Array（找出出现两次的元素）</title><link>https://111qqz.com/en/post/acm-icpc/2017/2017-04-12-leetcode-442-find-all-duplicates-in-an-array/</link><pubDate>Wed, 12 Apr 2017 15:21:23 +0000</pubDate><guid>https://111qqz.com/en/post/acm-icpc/2017/2017-04-12-leetcode-442-find-all-duplicates-in-an-array/</guid><description>&lt;p&gt;Given an array of integers, 1 ≤ a[i] ≤ &lt;em&gt;n&lt;/em&gt; (&lt;em&gt;n&lt;/em&gt; = size of array), some elements appear &lt;strong&gt;twice&lt;/strong&gt; and others appear &lt;strong&gt;once&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;Find all the elements that appear &lt;strong&gt;twice&lt;/strong&gt; in this array.&lt;/p&gt;</description></item><item><title>leetcode 48. Rotate Image (旋转方阵(in place))</title><link>https://111qqz.com/en/post/acm-icpc/2017/2017-04-12-leetcode-48-rotate-image/</link><pubDate>Wed, 12 Apr 2017 13:22:33 +0000</pubDate><guid>https://111qqz.com/en/post/acm-icpc/2017/2017-04-12-leetcode-48-rotate-image/</guid><description>&lt;p&gt;You are given an &lt;em&gt;n&lt;/em&gt; x &lt;em&gt;n&lt;/em&gt; 2D matrix representing an image.&lt;/p&gt;
&lt;p&gt;Rotate the image by 90 degrees (clockwise).&lt;/p&gt;
&lt;p&gt;Follow up:
Could you do this in-place?&lt;/p&gt;
&lt;p&gt;题意：给一个n*n的方阵，要求顺时针旋转90度。&lt;/p&gt;</description></item><item><title>leetcode 54. Spiral Matrix (矩阵蛇形取数)</title><link>https://111qqz.com/en/post/acm-icpc/2017/2017-04-11-leetcode-54-spiral-matrix/</link><pubDate>Tue, 11 Apr 2017 12:07:54 +0000</pubDate><guid>https://111qqz.com/en/post/acm-icpc/2017/2017-04-11-leetcode-54-spiral-matrix/</guid><description>&lt;p&gt;Given a matrix of &lt;em&gt;m&lt;/em&gt; x &lt;em&gt;n&lt;/em&gt; elements (&lt;em&gt;m&lt;/em&gt; rows, &lt;em&gt;n&lt;/em&gt; columns), return all elements of the matrix in spiral order.&lt;/p&gt;
&lt;p&gt;思路：。。。再次让我回想起高一的暑假。。。。&lt;/p&gt;</description></item><item><title>leetcode 55. Jump Game (dp)</title><link>https://111qqz.com/en/post/acm-icpc/2017/2017-04-11-leetcode-55-jump-game-dp/</link><pubDate>Tue, 11 Apr 2017 11:39:15 +0000</pubDate><guid>https://111qqz.com/en/post/acm-icpc/2017/2017-04-11-leetcode-55-jump-game-dp/</guid><description>&lt;p&gt;Given a collection of intervals, merge all overlapping intervals.&lt;/p&gt;
&lt;p&gt;For example,
Given &lt;code&gt;[1,3],[2,6],[8,10],[15,18]&lt;/code&gt;,
return &lt;code&gt;[1,6],[8,10],[15,18]&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;思路:dp[i]表示能否到达位置i&amp;hellip;无脑dp即可。。。&lt;/p&gt;</description></item><item><title>leetcode 56. Merge Intervals (模拟，求相交区间)</title><link>https://111qqz.com/en/post/acm-icpc/2017/2017-04-11-leetcode-56-merge-intervals/</link><pubDate>Tue, 11 Apr 2017 11:30:32 +0000</pubDate><guid>https://111qqz.com/en/post/acm-icpc/2017/2017-04-11-leetcode-56-merge-intervals/</guid><description>&lt;p&gt;Given a collection of intervals, merge all overlapping intervals.&lt;/p&gt;
&lt;p&gt;For example,
Given &lt;code&gt;[1,3],[2,6],[8,10],[15,18]&lt;/code&gt;,
return &lt;code&gt;[1,6],[8,10],[15,18]&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;思路：扫一遍即可。。&lt;/p&gt;
&lt;div class="highlight-wrapper"&gt;&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-cpp" data-lang="cpp"&gt;&lt;span class="line"&gt;&lt;span class="ln"&gt; 1&lt;/span&gt;&lt;span class="cl"&gt;&lt;span class="cm"&gt;/* ***********************************************
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="ln"&gt; 2&lt;/span&gt;&lt;span class="cl"&gt;&lt;span class="cm"&gt;Author :111qqz
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="ln"&gt; 3&lt;/span&gt;&lt;span class="cl"&gt;&lt;span class="cm"&gt;Created Time :2017年04月11日 星期二 19时15分30秒
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="ln"&gt; 4&lt;/span&gt;&lt;span class="cl"&gt;&lt;span class="cm"&gt;File Name :56.cpp
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="ln"&gt; 5&lt;/span&gt;&lt;span class="cl"&gt;&lt;span class="cm"&gt;************************************************ */&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="ln"&gt; 6&lt;/span&gt;&lt;span class="cl"&gt;&lt;span class="cm"&gt;/**
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="ln"&gt; 7&lt;/span&gt;&lt;span class="cl"&gt;&lt;span class="cm"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="ln"&gt; 8&lt;/span&gt;&lt;span class="cl"&gt;&lt;span class="cm"&gt; * Definition for an interval.
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="ln"&gt; 9&lt;/span&gt;&lt;span class="cl"&gt;&lt;span class="cm"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="ln"&gt;10&lt;/span&gt;&lt;span class="cl"&gt;&lt;span class="cm"&gt; * struct Interval {
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="ln"&gt;11&lt;/span&gt;&lt;span class="cl"&gt;&lt;span class="cm"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="ln"&gt;12&lt;/span&gt;&lt;span class="cl"&gt;&lt;span class="cm"&gt; * int start;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="ln"&gt;13&lt;/span&gt;&lt;span class="cl"&gt;&lt;span class="cm"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="ln"&gt;14&lt;/span&gt;&lt;span class="cl"&gt;&lt;span class="cm"&gt; * int end;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="ln"&gt;15&lt;/span&gt;&lt;span class="cl"&gt;&lt;span class="cm"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="ln"&gt;16&lt;/span&gt;&lt;span class="cl"&gt;&lt;span class="cm"&gt; * Interval() : start(0), end(0) {}
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="ln"&gt;17&lt;/span&gt;&lt;span class="cl"&gt;&lt;span class="cm"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="ln"&gt;18&lt;/span&gt;&lt;span class="cl"&gt;&lt;span class="cm"&gt; * Interval(int s, int e) : start(s), end(e) {}
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="ln"&gt;19&lt;/span&gt;&lt;span class="cl"&gt;&lt;span class="cm"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="ln"&gt;20&lt;/span&gt;&lt;span class="cl"&gt;&lt;span class="cm"&gt; * };
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="ln"&gt;21&lt;/span&gt;&lt;span class="cl"&gt;&lt;span class="cm"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="ln"&gt;22&lt;/span&gt;&lt;span class="cl"&gt;&lt;span class="cm"&gt; */&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="ln"&gt;23&lt;/span&gt;&lt;span class="cl"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="ln"&gt;24&lt;/span&gt;&lt;span class="cl"&gt;&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Solution&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="ln"&gt;25&lt;/span&gt;&lt;span class="cl"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="ln"&gt;26&lt;/span&gt;&lt;span class="cl"&gt;&lt;span class="k"&gt;public&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="ln"&gt;27&lt;/span&gt;&lt;span class="cl"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="ln"&gt;28&lt;/span&gt;&lt;span class="cl"&gt; &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;n&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="ln"&gt;29&lt;/span&gt;&lt;span class="cl"&gt; &lt;span class="k"&gt;static&lt;/span&gt; &lt;span class="kt"&gt;bool&lt;/span&gt; &lt;span class="nf"&gt;cmp&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;Interval&lt;/span&gt; &lt;span class="n"&gt;A&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="n"&gt;Interval&lt;/span&gt; &lt;span class="n"&gt;B&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="ln"&gt;30&lt;/span&gt;&lt;span class="cl"&gt; &lt;span class="p"&gt;{&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="ln"&gt;31&lt;/span&gt;&lt;span class="cl"&gt;	&lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;A&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;start&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;B&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;start&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="ln"&gt;32&lt;/span&gt;&lt;span class="cl"&gt; &lt;span class="p"&gt;}&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="ln"&gt;33&lt;/span&gt;&lt;span class="cl"&gt; &lt;span class="n"&gt;vector&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;Interval&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;merge&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;vector&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;Interval&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&amp;amp;&lt;/span&gt; &lt;span class="n"&gt;pi&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="ln"&gt;34&lt;/span&gt;&lt;span class="cl"&gt;	&lt;span class="n"&gt;vector&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;Interval&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;res&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="ln"&gt;35&lt;/span&gt;&lt;span class="cl"&gt;	&lt;span class="n"&gt;n&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;pi&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;size&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="ln"&gt;36&lt;/span&gt;&lt;span class="cl"&gt;	&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;n&lt;/span&gt;&lt;span class="o"&gt;==&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;res&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="ln"&gt;37&lt;/span&gt;&lt;span class="cl"&gt;	&lt;span class="n"&gt;sort&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;pi&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;begin&lt;/span&gt;&lt;span class="p"&gt;(),&lt;/span&gt;&lt;span class="n"&gt;pi&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;end&lt;/span&gt;&lt;span class="p"&gt;(),&lt;/span&gt;&lt;span class="n"&gt;cmp&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="ln"&gt;38&lt;/span&gt;&lt;span class="cl"&gt;	&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;l&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="n"&gt;r&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="ln"&gt;39&lt;/span&gt;&lt;span class="cl"&gt;	&lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="n"&gt;n&lt;/span&gt; &lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="ln"&gt;40&lt;/span&gt;&lt;span class="cl"&gt;	&lt;span class="p"&gt;{&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="ln"&gt;41&lt;/span&gt;&lt;span class="cl"&gt;	 &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;l&lt;/span&gt;&lt;span class="o"&gt;==-&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt;&lt;span class="n"&gt;r&lt;/span&gt;&lt;span class="o"&gt;==-&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="ln"&gt;42&lt;/span&gt;&lt;span class="cl"&gt;	 &lt;span class="p"&gt;{&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="ln"&gt;43&lt;/span&gt;&lt;span class="cl"&gt;		&lt;span class="n"&gt;l&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;pi&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="n"&gt;start&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="ln"&gt;44&lt;/span&gt;&lt;span class="cl"&gt;		&lt;span class="n"&gt;r&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;pi&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="n"&gt;end&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="ln"&gt;45&lt;/span&gt;&lt;span class="cl"&gt;		&lt;span class="k"&gt;continue&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="ln"&gt;46&lt;/span&gt;&lt;span class="cl"&gt;	 &lt;span class="p"&gt;}&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="ln"&gt;47&lt;/span&gt;&lt;span class="cl"&gt;	 &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;pi&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="n"&gt;start&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;=&lt;/span&gt;&lt;span class="n"&gt;r&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="ln"&gt;48&lt;/span&gt;&lt;span class="cl"&gt;	 &lt;span class="p"&gt;{&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="ln"&gt;49&lt;/span&gt;&lt;span class="cl"&gt;		&lt;span class="n"&gt;r&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;max&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;r&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="n"&gt;pi&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="n"&gt;end&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="ln"&gt;50&lt;/span&gt;&lt;span class="cl"&gt;		&lt;span class="k"&gt;continue&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="ln"&gt;51&lt;/span&gt;&lt;span class="cl"&gt;	 &lt;span class="p"&gt;}&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="ln"&gt;52&lt;/span&gt;&lt;span class="cl"&gt;	 &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;pi&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="n"&gt;start&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;r&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="ln"&gt;53&lt;/span&gt;&lt;span class="cl"&gt;	 &lt;span class="p"&gt;{&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="ln"&gt;54&lt;/span&gt;&lt;span class="cl"&gt;		&lt;span class="n"&gt;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;push_back&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;Interval&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;l&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="n"&gt;r&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="ln"&gt;55&lt;/span&gt;&lt;span class="cl"&gt;		&lt;span class="n"&gt;l&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;pi&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="n"&gt;start&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="ln"&gt;56&lt;/span&gt;&lt;span class="cl"&gt;		&lt;span class="n"&gt;r&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;pi&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="n"&gt;end&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="ln"&gt;57&lt;/span&gt;&lt;span class="cl"&gt;		&lt;span class="k"&gt;continue&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="ln"&gt;58&lt;/span&gt;&lt;span class="cl"&gt;	 &lt;span class="p"&gt;}&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="ln"&gt;59&lt;/span&gt;&lt;span class="cl"&gt;	&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="ln"&gt;60&lt;/span&gt;&lt;span class="cl"&gt;	&lt;span class="c1"&gt;//最后一组不要忘记
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="ln"&gt;61&lt;/span&gt;&lt;span class="cl"&gt;	&lt;span class="n"&gt;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;push_back&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;Interval&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;l&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="n"&gt;r&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="ln"&gt;62&lt;/span&gt;&lt;span class="cl"&gt;	&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;siz&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;size&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="ln"&gt;63&lt;/span&gt;&lt;span class="cl"&gt;	&lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="n"&gt;siz&lt;/span&gt; &lt;span class="p"&gt;;&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="n"&gt;printf&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;&amp;#34;%d &amp;#34;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="n"&gt;res&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="n"&gt;start&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="n"&gt;res&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="n"&gt;end&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="ln"&gt;64&lt;/span&gt;&lt;span class="cl"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="ln"&gt;65&lt;/span&gt;&lt;span class="cl"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="ln"&gt;66&lt;/span&gt;&lt;span class="cl"&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;res&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="ln"&gt;67&lt;/span&gt;&lt;span class="cl"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="ln"&gt;68&lt;/span&gt;&lt;span class="cl"&gt; &lt;span class="p"&gt;}&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="ln"&gt;69&lt;/span&gt;&lt;span class="cl"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="ln"&gt;70&lt;/span&gt;&lt;span class="cl"&gt;&lt;span class="p"&gt;};&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;</description></item><item><title>leetocde 59. Spiral Matrix II (模拟)</title><link>https://111qqz.com/en/post/acm-icpc/2017/2017-04-11-59-spiral-matrix-ii/</link><pubDate>Tue, 11 Apr 2017 11:07:52 +0000</pubDate><guid>https://111qqz.com/en/post/acm-icpc/2017/2017-04-11-59-spiral-matrix-ii/</guid><description>&lt;p&gt;Given an integer &lt;em&gt;n&lt;/em&gt;, generate a square matrix filled with elements from 1 to _n_2 in spiral order.&lt;/p&gt;
&lt;p&gt;思路：仿佛回到高一的那个暑假。。。&lt;/p&gt;</description></item><item><title>leetocde 63. Unique Paths II</title><link>https://111qqz.com/en/post/acm-icpc/2017/2017-04-11-63-unique-paths-ii/</link><pubDate>Tue, 11 Apr 2017 10:50:57 +0000</pubDate><guid>https://111qqz.com/en/post/acm-icpc/2017/2017-04-11-63-unique-paths-ii/</guid><description>&lt;p&gt;Follow up for &amp;ldquo;Unique Paths&amp;rdquo;:&lt;/p&gt;
&lt;p&gt;Now consider if some obstacles are added to the grids. How many unique paths would there be?&lt;/p&gt;
&lt;p&gt;An obstacle and empty space is marked as &lt;code&gt;1&lt;/code&gt; and &lt;code&gt;0&lt;/code&gt; respectively in the grid.&lt;/p&gt;</description></item><item><title>leetcode 64. Minimum Path Sum (二维dp)</title><link>https://111qqz.com/en/post/acm-icpc/2017/2017-04-10-leetcode-64-minimum-path-sum/</link><pubDate>Mon, 10 Apr 2017 02:35:20 +0000</pubDate><guid>https://111qqz.com/en/post/acm-icpc/2017/2017-04-10-leetcode-64-minimum-path-sum/</guid><description>&lt;p&gt;Given a &lt;em&gt;m&lt;/em&gt; x &lt;em&gt;n&lt;/em&gt; grid filled with non-negative numbers, find a path from top left to bottom right which &lt;em&gt;minimizes&lt;/em&gt; the sum of all numbers along its path.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; You can only move either down or right at any point in time.&lt;/p&gt;</description></item><item><title>leetcode 73. Set Matrix Zeroes (矩阵置0，乱搞)</title><link>https://111qqz.com/en/post/acm-icpc/2017/2017-04-10-leetcode-73-set-matrix-zeroes/</link><pubDate>Mon, 10 Apr 2017 01:16:43 +0000</pubDate><guid>https://111qqz.com/en/post/acm-icpc/2017/2017-04-10-leetcode-73-set-matrix-zeroes/</guid><description>&lt;p&gt;Given a &lt;em&gt;m&lt;/em&gt; x &lt;em&gt;n&lt;/em&gt; matrix, if an element is 0, set its entire row and column to 0. Do it in place.&lt;/p&gt;
&lt;p&gt;&lt;a href="https://leetcode.com/problems/set-matrix-zeroes/" target="_blank" rel="noreferrer"&gt;click to show follow up.&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;**Follow up:**Did you use extra space?
A straight forward solution using O(&lt;em&gt;m__n&lt;/em&gt;) space is probably a bad idea.
A simple improvement uses O(&lt;em&gt;m&lt;/em&gt; + &lt;em&gt;n&lt;/em&gt;) space, but still not the best solution.
Could you devise a constant space solution?&lt;/p&gt;</description></item><item><title>leetcode 238. Product of Array Except Self (乱搞)</title><link>https://111qqz.com/en/post/acm-icpc/2017/2017-04-09-leetcode-238-product-of-array-except-self/</link><pubDate>Sun, 09 Apr 2017 11:50:05 +0000</pubDate><guid>https://111qqz.com/en/post/acm-icpc/2017/2017-04-09-leetcode-238-product-of-array-except-self/</guid><description>&lt;p&gt;Given an array of &lt;em&gt;n&lt;/em&gt; integers where &lt;em&gt;n&lt;/em&gt; &amp;gt; 1, &lt;code&gt;nums&lt;/code&gt;, return an array &lt;code&gt;output&lt;/code&gt; such that &lt;code&gt;output[i]&lt;/code&gt; is equal to the product of all the elements of &lt;code&gt;nums&lt;/code&gt; except &lt;code&gt;nums[i]&lt;/code&gt;.&lt;/p&gt;</description></item><item><title>leetcode 79. Word Search (dfs)</title><link>https://111qqz.com/en/post/acm-icpc/2017/2017-04-07-leetcode-79-word-search-dfs/</link><pubDate>Fri, 07 Apr 2017 06:59:26 +0000</pubDate><guid>https://111qqz.com/en/post/acm-icpc/2017/2017-04-07-leetcode-79-word-search-dfs/</guid><description>&lt;p&gt;Given a 2D board and a word, find if the word exists in the grid.&lt;/p&gt;
&lt;p&gt;The word can be constructed from letters of sequentially adjacent cell, where &amp;ldquo;adjacent&amp;rdquo; cells are those horizontally or vertically neighboring. The same letter cell may not be used more than once.&lt;/p&gt;</description></item><item><title>leetcode 80 Remove Duplicates from Sorted Array II （有序数组去除重复元素）</title><link>https://111qqz.com/en/post/acm-icpc/2017/2017-04-05-leetcode-80-remove-duplicates-from-sorted-array-ii/</link><pubDate>Wed, 05 Apr 2017 13:36:44 +0000</pubDate><guid>https://111qqz.com/en/post/acm-icpc/2017/2017-04-05-leetcode-80-remove-duplicates-from-sorted-array-ii/</guid><description>&lt;p&gt;Follow up for &amp;ldquo;Remove Duplicates&amp;rdquo;:
What if duplicates are allowed at most &lt;em&gt;twice&lt;/em&gt;?&lt;/p&gt;
&lt;p&gt;For example,
Given sorted array &lt;em&gt;nums&lt;/em&gt; = &lt;code&gt;[1,1,1,2,2,3]&lt;/code&gt;,&lt;/p&gt;
&lt;p&gt;Your function should return length = &lt;code&gt;5&lt;/code&gt;, with the first five elements of &lt;em&gt;nums&lt;/em&gt; being &lt;code&gt;1&lt;/code&gt;, &lt;code&gt;1&lt;/code&gt;, &lt;code&gt;2&lt;/code&gt;, &lt;code&gt;2&lt;/code&gt; and &lt;code&gt;3&lt;/code&gt;. It doesn&amp;rsquo;t matter what you leave beyond the new length.&lt;/p&gt;</description></item><item><title>leetcode 81. Search in Rotated Sorted Array II (有重复元素的旋转数组找给定值)</title><link>https://111qqz.com/en/post/acm-icpc/2017/2017-04-05-leetcode-81-search-in-rotated-sorted-array-ii/</link><pubDate>Wed, 05 Apr 2017 13:17:51 +0000</pubDate><guid>https://111qqz.com/en/post/acm-icpc/2017/2017-04-05-leetcode-81-search-in-rotated-sorted-array-ii/</guid><description>&lt;p&gt;Suppose an array sorted in ascending order is rotated at some pivot unknown to you beforehand.&lt;/p&gt;
&lt;p&gt;(i.e., &lt;code&gt;0 1 2 4 5 6 7&lt;/code&gt; might become &lt;code&gt;4 5 6 7 0 1 2&lt;/code&gt;).&lt;/p&gt;</description></item><item><title>leetcode 289. Game of Life (模拟)</title><link>https://111qqz.com/en/post/acm-icpc/2017/2017-04-05-leetcode-289-game-of-life/</link><pubDate>Wed, 05 Apr 2017 12:03:28 +0000</pubDate><guid>https://111qqz.com/en/post/acm-icpc/2017/2017-04-05-leetcode-289-game-of-life/</guid><description>&lt;p&gt;According to the &lt;a href="https://en.wikipedia.org/wiki/Conways_Game_of_Life" target="_blank" rel="noreferrer"&gt;Wikipedia&amp;rsquo;s article&lt;/a&gt;: &amp;ldquo;The &lt;strong&gt;Game of Life&lt;/strong&gt;, also known simply as &lt;strong&gt;Life&lt;/strong&gt;, is a cellular automaton devised by the British mathematician John Horton Conway in 1970.&amp;rdquo;&lt;/p&gt;
&lt;p&gt;Given a &lt;em&gt;board&lt;/em&gt; with &lt;em&gt;m&lt;/em&gt; by &lt;em&gt;n&lt;/em&gt; cells, each cell has an initial state &lt;em&gt;live&lt;/em&gt; (1) or &lt;em&gt;dead&lt;/em&gt; (0). Each cell interacts with its &lt;a href="https://en.wikipedia.org/wiki/Moore_neighborhood" target="_blank" rel="noreferrer"&gt;eight neighbors&lt;/a&gt; (horizontal, vertical, diagonal) using the following four rules (taken from the above Wikipedia article):&lt;/p&gt;</description></item><item><title>leetcode 90. Subsets II (枚举子集)</title><link>https://111qqz.com/en/post/acm-icpc/2017/2017-04-05-90-leetcode-subsets-ii-e69e9ae4b8bee5ad90e99b86/</link><pubDate>Wed, 05 Apr 2017 10:45:02 +0000</pubDate><guid>https://111qqz.com/en/post/acm-icpc/2017/2017-04-05-90-leetcode-subsets-ii-e69e9ae4b8bee5ad90e99b86/</guid><description>&lt;p&gt;Given a collection of integers that might contain duplicates, &lt;strong&gt;&lt;em&gt;nums&lt;/em&gt;&lt;/strong&gt;, return all possible subsets.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; The solution set must not contain duplicate subsets.&lt;/p&gt;
&lt;p&gt;For example,
If &lt;strong&gt;&lt;em&gt;nums&lt;/em&gt;&lt;/strong&gt; = &lt;code&gt;[1,2,2]&lt;/code&gt;, a solution is:&lt;/p&gt;</description></item><item><title>leetcode 287. Find the Duplicate Number (floyd判圈算法找重复元素)</title><link>https://111qqz.com/en/post/acm-icpc/2017/2017-04-05-leetcode-287-find-the-duplicate-number/</link><pubDate>Wed, 05 Apr 2017 07:31:49 +0000</pubDate><guid>https://111qqz.com/en/post/acm-icpc/2017/2017-04-05-leetcode-287-find-the-duplicate-number/</guid><description>&lt;p&gt;Given an array &lt;em&gt;nums&lt;/em&gt; containing &lt;em&gt;n&lt;/em&gt; + 1 integers where each integer is between 1 and &lt;em&gt;n&lt;/em&gt; (inclusive), prove that at least one duplicate number must exist. Assume that there is only one duplicate number, find the duplicate one.&lt;/p&gt;</description></item><item><title>leetcode 532. K-diff Pairs in an Array （找差为k的数对）</title><link>https://111qqz.com/en/post/acm-icpc/2017/2017-04-05-532-leetcode-k-diff-pairs-in-an-array/</link><pubDate>Wed, 05 Apr 2017 06:53:02 +0000</pubDate><guid>https://111qqz.com/en/post/acm-icpc/2017/2017-04-05-532-leetcode-k-diff-pairs-in-an-array/</guid><description>&lt;p&gt;Given an array of integers and an integer &lt;strong&gt;k&lt;/strong&gt;, you need to find the number of &lt;strong&gt;unique&lt;/strong&gt; k-diff pairs in the array. Here a &lt;strong&gt;k-diff&lt;/strong&gt; pair is defined as an integer pair (i, j), where &lt;strong&gt;i&lt;/strong&gt; and &lt;strong&gt;j&lt;/strong&gt; are both numbers in the array and their &lt;a href="https://en.wikipedia.org/wiki/Absolute_difference" target="_blank" rel="noreferrer"&gt;absolute difference&lt;/a&gt; is &lt;strong&gt;k&lt;/strong&gt;.&lt;/p&gt;</description></item><item><title>leetcode 448. Find All Numbers Disappeared in an Array(寻找所有消失的元素）</title><link>https://111qqz.com/en/post/acm-icpc/2017/2017-04-05-leetcode-448-find-all-numbers-disappeared-in-an-array/</link><pubDate>Wed, 05 Apr 2017 06:19:06 +0000</pubDate><guid>https://111qqz.com/en/post/acm-icpc/2017/2017-04-05-leetcode-448-find-all-numbers-disappeared-in-an-array/</guid><description>&lt;p&gt;Given an array of integers where 1 ≤ a[i] ≤ &lt;em&gt;n&lt;/em&gt; (&lt;em&gt;n&lt;/em&gt; = size of array), some elements appear twice and others appear once.&lt;/p&gt;
&lt;p&gt;Find all the elements of [1, &lt;em&gt;n&lt;/em&gt;] inclusive that do not appear in this array.&lt;/p&gt;</description></item></channel></rss>