原创 leetcode:453. Minimum Moves to Equal Array Elements

Given a non-empty integer array of size n, find the minimum number of moves required to make all array elements eq

原创 leetcode:216. Combination Sum III

216. Combination Sum III 大意是說在1-9中選k個不同的數,使他們的和是n,返回是所有的選擇。 Example 1: 輸入: k = 3, n = 7 輸出:[[1,2,4]] Example

原创 435. Non-overlapping Intervals

Given a collection of intervals, find the minimum number of intervals you need to remove to make the rest of the in

原创 423. Reconstruct Original Digits from English

Given a non-empty string containing an out-of-order English representation of digits 0-9, output the digits in asce

原创 33. Search in Rotated Sorted Array

Suppose a sorted array is rotated at some pivot unknown to you beforehand. (i.e., 0 1 2 4 5 6 7 might become 4 5 6

原创 86. Partition List

Given a linked list and a value x, partition it such that all nodes less than x come before nodes greater than or e

原创 leetcode:447. Number of Boomerangs

原題的輸入輸出: **Input:** [[0,0],[1,0],[2,0]] **Output:** 2 **Explanation:** The two boomerangs are **[[1,0],[0,0],[2,0

原创 451. Sort Characters By Frequency

Given a string, sort it in decreasing order based on the frequency of characters. 就是按頻數來排序唄!! 我的做法是先寫成字典,然後用sorte

原创 python bisect模塊的應用方法與leetcode:436. Find Right Interval

這個模塊只有幾個函數,一旦決定使用二分搜索時,立馬要想到使用這個模塊.     >>>import bisect     >>>dir(bisect)     [‘builtins‘, ‘cached‘, ‘doc‘, ‘fi

原创 437. Path Sum III

root = [10,5,-3,3,2,null,11,3,-2,null,1], sum = 8 10 / \ 5 -3 / \ \ 3 2 11 / \ \

原创 153和154. Find Minimum in Rotated Sorted Array II

先來看154 Follow up for “Find Minimum in Rotated Sorted Array”: What if duplicates are allowed? Would this affect

原创 455. Assign Cookies

Assume you are an awesome parent and want to give your children some cookies. But, you should give each child at mo

原创 紅黑樹(未完待續)

二叉查找樹 特點 若任意結點的左子樹不空,則左子樹上所有結點的值均小於它的根結點的值; 若任意結點的右子樹不空,則右子樹上所有結點的值均大於它的根結點的值; 任意結點的左、右子樹也分別爲二叉查找樹。 沒有鍵值相等的結點(no d

原创 438. Find 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 low

原创 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 l