原创 4Sum

題目: Given an array S of n integers, are there elements a, b, c, and d in S such that a + b + c + d = target? Find

原创 Integer to Roman

羅馬數字: 1~9: {“I”, “II”, “III”, “IV”, “V”, “VI”, “VII”, “VIII”, “IX”}; 10~90: {“X”, “XX”, “XXX”, “XL”, “L”, “LX”, “L

原创 動態規劃方法

1、思想:避免重複的計算,先將計算過的值保存下來,如果發現有相同的步驟,直接將事先保存好的值拿出來。 動態規劃其實質上是通過開闢記錄表,記錄已求解過的結果,當再次需要求解的時候,可以直接到那個記錄表中去查找,從而避

原创 Median of Two Sorted Arrays

1、一提到中位數就要考慮數組的個數是奇數還是偶數; 2、涉及到排序數組的求和、求中位數這類的問題都要想到用二分法的思想; 題目: There are two sorted arrays nums1 and nums2 of

原创 3Sum Closest

題目: Given an array S of n integers, find three integers in S such that the sum is closest to a given number, targe

原创 3Sum

1、結果爲vector < vector> res這樣的數組時,要記得先把res進行clear; 題目: Given an array S of n integers, are there elements a, b, c i

原创 Longest Common Prefix

題目: Write a function to find the longest common prefix string amongst an array of strings. 寫一個函數找到一組字符串的最長公共前綴。

原创 Container With Most Water

題目: Given n non-negative integers a1, a2, …, an, where each represents a point at coordinate (i, ai). n vertical l

原创 Merge Two Sorted Lists

題目: Merge two sorted linked lists and return it as a new list. The new list should be made by splicing together th

原创 Remove Nth Node From End of List

1、遇到鏈表的問題,首先要記得判斷head==NULL; 2、鏈表中查找某個結點時,通常用三個輔助指針來表示; 題目: Given a linked list, remove the nth node from the

原创 Valid Parentheses

1、Valid Parentheses 括號的匹配 題目: Given a string containing just the characters ‘(‘, ‘)’, ‘{‘, ‘}’, ‘[’ and ‘]’, dete

原创 Regular Expression Matching

題目: Implement regular expression matching with support for ‘.’ and ‘*’. ‘.’ Matches any single character. ‘*’ Mat

原创 ZigZag Conversion

找規律的題:通過從簡入繁的方法發現規律,從而進行計算; 題目: The string “PAYPALISHIRING” is written in a zigzag pattern on a given number of r

原创 Roman to Integer

題目: Given a roman numeral, convert it to an integer. Input is guaranteed to be within the range from 1 to 3999. 思

原创 Divide Two Integers

1、有數字判斷時,先看這個數字是正是負; 2、注意最大範圍2147483647,和-2147483648的判斷; 3、這個題是要背住的; 題目: Divide two integers without using multipli