Leetcode-Quesition-30: Substring with Concatenation of All Words

Original Link:

https://leetcode.com/problems/substring-with-concatenation-of-all-words/

Solution:

【Approach #1】Native Method

【Approach#2】

 

Leetcode-Question-65: Valid Number

原文链接:

https://leetcode.com/problems/valid-number/

解析:

 

Leetcode-Question-647: Palindromic Substrings

原文链接:
https://leetcode.com/problems/palindromic-substrings/

解析:

参考:

https://discuss.leetcode.com/topic/96822/python-straightforward-with-explanation-bonus-o-n-solution

 

Leetcode-Question-672: Bulb Switcher II

原文链接:

https://leetcode.com/problems/bulb-switcher-ii/

解析:

 

Leetcode-Question-345: Reverse Vowels of a String

https://leetcode.com/problems/reverse-vowels-of-a-string

解析:

或者:

 

Leetcode-Question-460: LFU Cache

原文链接:
https://leetcode.com/problems/lfu-cache/

题目描述:
460. LFU Cache

Design and implement a data structure for Least Frequently Used (LFU) cache. It should support the following operations: get and put.

get(key) – Get the value (will always be positive) of the key if the key exists in the cache, otherwise return -1.
put(key, value) – Set or insert the value if the key is not already present. When the cache reaches its capacity, it should invalidate the least frequently used item before inserting a new item. For the purpose of this problem, when there is a tie (i.e., two or more keys that have the same frequency), the least recently used key would be evicted.

Follow up:
Could you do both operations in O(1) time complexity?

Example:

解答:
法一:

法二:

 

Leetcode-Question-436: Find Right Interval

原文链接:
https://leetcode.com/contest/11/problems/find-right-interval/

题目描述:
436. Find Right Interval
Difficulty: Medium

Given a set of intervals, for each of the interval i, check if there exists an interval j whose start point is bigger than or equal to the end point of the interval i, which can be called that j is on the “right” of i.

For any interval i, you need to store the minimum interval j’s index, which means that the interval j has the minimum start point to build the “right” relationship for interval i. If the interval j doesn’t exist, store -1 for the interval i. Finally, you need output the stored value of each interval as an array.

Note:

  1. You may assume the interval’s end point is always bigger than its start point.
  2. You may assume none of these intervals have the same start point.

Example 1:

Example 2:

Example 3:

解析:

Updated: 2017.10.01
笑,当初为什么不用std::map,而用了std::set<std::pair<int, int>> 呢。

 

Leetcode-Question-441: Arranging Coins

原文链接:
https://leetcode.com/contest/11/problems/arranging-coins/

题目描述:
441. Arranging Coins
Difficulty: Easy

You have a total of n coins that you want to form in a staircase shape, where every k-th row must have exactly coins.

Given n, find the total number of full staircase rows that can be formed.

n is a non-negative integer and fits within the range of a 32-bit signed integer.

Example 1:

Example 2:

解析:

或者,

 

Leetcode-Question-435: Non-overlapping Intervals

原文链接:
https://leetcode.com/contest/11/problems/non-overlapping-intervals/

题目描述:
435. Non-overlapping Intervals
Difficulty: Medium

Given a collection of intervals, find the minimum number of intervals you need to remove to make the rest of the intervals non-overlapping.

Note:

  1. You may assume the interval’s end point is always bigger than its start point.
  2. Intervals like [1,2] and [2,3] have borders “touching” but they don’t overlap each other.

Example 1:

Example 2:

Example 3:

解析:

 

Leetcode-Question-422: Find All Duplicates in an Array

原文链接:
https://leetcode.com/problems/find-all-duplicates-in-an-array/

题目描述:
442. Find All Duplicates in an Array
Difficulty: Medium

Given an array of integers, 1 ≤ a[i] ≤ n (n = size of array), some elements appear twice and others appear once.

Find all the elements that appear twice in this array.

Could you do it without extra space and in O(n) runtime?

Example:

解析: