标签 / 算法 · 28 篇
259. 3Sum Smaller
Given an array of n integers nums and a target, find the number of index triplets i, j, k with 0 Input: nums =…
16. 3Sum Closest
Given an array nums of n integers and an integer target , find three integers in nums such that the sum is clo…
186. Reverse Words in a String II
Given an input string , reverse the string word by word. Example: Input: ["t","h","e"," ","s","k","y"," ","i",…
206. Reverse Linked List
Reverse a singly linked list. Example: Input: 1 2 3 4 5 NULL Output: 5 4 3 2 1 NULL Follow up: A linked list c…
53. Maximum Subarray
Given an integer array nums, find the contiguous subarray (containing at least one number) which has the large…
14. Longest Common Prefix
Write a function to find the longest common prefix string amongst an array of strings. If there is no common p…
371. Sum of Two Integers
Calculate the sum of two integers a and b, but you are not allowed to use the operator + and . Example: Given …
167. Two Sum II - Input array is sorted
Given an array of integers that is already sorted in ascending order , find two numbers such that they add up …
292. Nim Game
You are playing the following Nim Game with your friend: There is a heap of stones on the table, each time one…
8. String to Integer (atoi)
Implement atoi which converts a string to an integer. The function first discards as many whitespace character…
6. ZigZag Conversion
The string "PAYPALISHIRING" is written in a zigzag pattern on a given number of rows like this: (you may want …
458. Poor Pigs
There are 1000 buckets, one and only one of them contains poison, the rest are filled with water. They all loo…
5. Longest Palindromic Substring
Given a string s, find the longest palindromic substring in s. You may assume that the maximum length of s is …
21. 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…
9. Palindrome Number
Determine whether an integer is a palindrome. Do this without extra space. 声明一个临时变量 sum ,辗转相除以及辗转相乘,然后比较 sum 和…
121. Best Time to Buy and Sell Stock
Say you have an array for which the i^th element is the price of a given stock on day i. If you were only perm…
排序算法
排序算法是最基本最常用的算法,是算法与数据结构的基础,也是面试中常见的一类问题。 插入排序方法类似于我们整理手上的扑克牌,在数据量小的时候是一种高效的的排序算法。 插入排序通常只需要用到O(1)的额外空间: 1. 从第一…
345. Reverse Vowels of a String
Write a function that takes a string as input and reverse only the vowels of a string. Example 1: Given s = "h…
231. Power of Two
Given an integer, write a function to determine if it is a power of two. 循环除以2看是否等于1。 或者 整型的范围是 2147483648 ( 2…
326. Power of Three
Given an integer, write a function to determine if it is a power of three. Follow up: Could you do it without …
463. Island Perimeter
You are given a map in form of a two dimensional integer grid where 1 represents land and 0 represents water. …
155. Min Stack
Design a stack that supports push, pop, top, and retrieving the minimum element in constant time. push(x) Push…
66. Plus One
Given a non negative integer represented as a non empty array of digits, plus one to the integer. You may assu…
20. Valid Parentheses
Given a string containing just the characters '(' , ')' , '{' , '}' , '[' and ']' , determine if the input str…
657. Judge Route Circle
Initially, there is a Robot at position (0, 0). Given a sequence of its moves, judge if this robot makes a cir…
8皇后问题
如何能够在8×8的国际象棋棋盘上放置8个皇后,使得任何一个皇后都无法直接吃掉其他的皇后?高斯认为有76种方案。1854年在柏林的象棋杂志上不同的作者发表了40种不同的解,后来有人用图论的方法解出92种结果。 因为在国际象…
760 Find Anagram Mappings
Given two lists Aand B , and B is an anagram of A . B is an anagram of A means B is made by randomizing the or…
1. Two Sum
Given an array of integers, return indices of the two numbers such that they add up to a specific target. You …