![](https://img-blog.csdnimg.cn/20201014180756754.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
leet code
文章平均质量分 77
yxcbluesky
这个作者很懒,什么都没留下…
展开
-
N-Queens
The n-queens puzzle is the problem of placing n queens on an n×n chessboard such that no two queens attack each other. Given an integer n, return all distinct solutions to the n-queens puzzle. Eac原创 2014-09-20 22:31:20 · 300 阅读 · 0 评论 -
string to integer
class Solution { public: int atoi(const char *str) { int len = strlen(str); int i,k; int64_t j = 1; int result = 0; bool positive = true; int ma原创 2014-09-02 13:50:51 · 224 阅读 · 0 评论 -
sqrt(x)
Implement int sqrt(int x). Compute and return the square root of x.原创 2014-09-01 18:26:05 · 283 阅读 · 0 评论 -
pow(x,n)
题意:要求实现pow(x,n) 思路:原创 2014-09-02 14:36:00 · 316 阅读 · 0 评论 -
Max Points on a Line
Given n points on a 2D plane, find the maximum number of points that lie on the same straight line. 思路:原创 2014-09-24 12:50:38 · 392 阅读 · 0 评论 -
Longest Valid Parentheses
Given a string containing just the characters '(' and ')', find the length of the longest valid (well-formed) parentheses substring. For "(()", the longest valid parentheses substring is "()", wh原创 2014-09-22 16:37:29 · 370 阅读 · 0 评论 -
Add Binary
给出2个二进制字符串,原创 2014-08-30 18:58:46 · 461 阅读 · 0 评论 -
Merge k Sorted Lists
Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity. 思路原创 2014-09-14 18:18:06 · 331 阅读 · 0 评论 -
Valid Palindrome
Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignoring cases. For example, "A man, a plan, a canal: Panama" is a palindrome. "race a car" is not a pa原创 2014-09-14 11:38:45 · 355 阅读 · 0 评论 -
Set Matrix Zeroes
Given a m x n matrix, if an element is 0, set its entire row and column to 0. Do it in place. click to show follow up. Follow up: Did you use extra space? A straight forward solution using O(m原创 2014-09-14 11:02:05 · 483 阅读 · 0 评论 -
3sum closest
Given an array S of n integers, find three integers in S 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 exact原创 2014-09-13 09:35:42 · 306 阅读 · 0 评论 -
Decode Ways
A message containing letters from A-Z is being encoded to numbers using the following mapping: 'A' -> 1 'B' -> 2 ... 'Z' -> 26 Given an encoded message containing digits, determine the total nu原创 2014-09-12 16:58:40 · 308 阅读 · 0 评论 -
valid number
Validate if a given string is numeric. Some examples: "0" => true " 0.1 " => true "abc" => false "1 a" => false "2e10" => true Note: It is intended for the problem statement to be ambiguo原创 2014-09-13 16:24:26 · 458 阅读 · 0 评论 -
最长公共前缀
题目:给出一个数组,数组中每个元素原创 2014-08-30 14:52:26 · 381 阅读 · 0 评论 -
Reverse Words in a String
Given an input string, reverse the string word by word. For example, Given s = "the sky is blue", return "blue is sky the". 题意:其实这道题比较简单,就是需要处理一些细节:liru原创 2014-08-30 16:02:48 · 376 阅读 · 0 评论 -
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 all unique quadruplets in the array which gives the sum of target. Note: Elements原创 2014-09-13 15:32:59 · 353 阅读 · 0 评论 -
Divide Two Integers
Divide two integers without using multiplication, division and mod operator. 思路:这道题s原创 2014-09-13 09:01:03 · 299 阅读 · 0 评论 -
Triangle
Given a triangle, find the minimum path sum from top to bottom. Each step you may move to adjacent numbers on the row below. For example, given the following triangle [ [2], [3,4], [6,原创 2014-09-24 17:51:55 · 382 阅读 · 0 评论 -
path sum
Given a binary tree and a sum, determine if the tree has a root-to-leaf path such that adding up all the values along the path equals the given sum. For example: Given the below binary tree and sum原创 2014-09-02 16:04:03 · 360 阅读 · 0 评论 -
求二叉树的最小深度
if (root == NULL) { return 0; } stack S; stack Depth; int val = 0; int min = 999999; while(root != NULL || !S.empty())原创 2014-09-02 16:26:00 · 375 阅读 · 0 评论 -
Word Ladder II
Given two words (start and end), and a dictionary, find all shortest transformation sequence(s) from start to end, such that: Only one letter can be changed at a timeEach intermediate word must exi原创 2014-09-30 23:39:22 · 523 阅读 · 0 评论 -
word break II
Given a string s and a dictionary of words dict, add spaces in s to construct a sentence where each word is a valid dictionary word. Return all such possible sentences. For example, given s = "cats原创 2014-09-28 21:03:39 · 387 阅读 · 0 评论 -
word break
Given a string s and a dictionary of words dict, determine if s can be segmented into a space-separated sequence of one or more dictionary words. For example, given s = "leetcode", dict = ["leet",原创 2014-09-28 14:04:20 · 365 阅读 · 0 评论 -
Valid Sudoku
Determine if a Sudoku is valid, according to: Sudoku Puzzles - The Rules. The Sudoku board could be partially filled, where empty cells are filled with the character '.'. A partially fille原创 2014-10-21 20:53:00 · 333 阅读 · 0 评论 -
Next Permutation
Implement next permutation, which rearranges numbers into the lexicographically next greater permutation of numbers. If such arrangement is not possible, it must rearrange it as the lowest possible o原创 2014-09-18 15:32:15 · 322 阅读 · 0 评论 -
Unique Binary Search Trees
Given n, how many structurally unique BST's (binary search trees) that store values 1...n? For example, Given n = 3, there are a total of 5 unique BST's. 1 3 3 2 1 \原创 2014-09-18 15:04:07 · 265 阅读 · 0 评论 -
Permutations II
Given a collection of numbers that might contain duplicates, return all possible unique permutations. For example, [1,1,2] have the following unique permutations: [1,1,2], [1,2,1], and [2,1原创 2014-09-17 22:48:08 · 240 阅读 · 0 评论 -
Binary Tree Zigzag Level Order Traversal
Given a binary tree, return the zigzag level order traversal of its nodes' values. (ie, from left to right, then right to left for the next level and alternate between). For example: Given binary原创 2014-09-24 21:00:10 · 346 阅读 · 0 评论 -
Trapping Rain Water
Given n non-negative integers representing an elevation map where the width of each bar is 1, compute how much water it is able to trap after raining. For example, Given [0,1,0,2,1,0,1,3,2,1,2,1]原创 2014-09-17 13:16:04 · 402 阅读 · 0 评论 -
Combinations
Given two integers n and k, return all possible combinations of k numbers out of 1 ... n. For example, If n = 4 and k = 2, a solution is: [ [2,4], [3,4], [2,3], [1,2], [1,3], [1,4], ]原创 2014-09-17 15:08:25 · 261 阅读 · 0 评论 -
Search a 2D Matrix
Write an efficient algorithm that searches for a value in an m x n matrix. This matrix has the following properties: Integers in each row are sorted from left to right.The first integer of each原创 2014-09-17 14:24:57 · 339 阅读 · 0 评论 -
Palindrome Partitioning
Given a string s, partition s such that every substring of the partition is a palindrome. Return all possible palindrome partitioning of s. For example, given s = "aab", Return [ ["aa","b"],原创 2014-09-25 00:24:45 · 312 阅读 · 0 评论 -
two sum
Given an array of integers, find two numbers such that they add up to a specific target number. The function twoSum should return indices of the two numbers such that they add up to the target, whe原创 2014-09-03 11:06:40 · 305 阅读 · 0 评论 -
Permutations
Given a collection of numbers, return all possible permutations. For example, [1,2,3] have the following permutations: [1,2,3], [1,3,2], [2,1,3], [2,3,1], [3,1,2], and [3,2,1].原创 2014-09-15 23:24:47 · 350 阅读 · 0 评论 -
Recover Binary Search Tree
Two elements of a binary search tree (BST) are swapped by mistake. Recover the tree without changing its structure. Note: A solution using O(n) space is pretty straight forward. Could you devise a原创 2014-09-26 11:20:41 · 308 阅读 · 0 评论 -
Multiply Strings
Given two numbers represented as strings, return multiplication of the numbers as a string. Note: The numbers can be arbitrarily large and are non-negative.原创 2014-09-01 19:48:53 · 308 阅读 · 0 评论 -
Pascal's Triangle系列
Given numRows, generate the first numRows of Pascal's triangle. For example, given numRows = 5, Return [ [1], [1,1], [1,2,1], [1,3,3,1], [1,4,6,4,1] ]原创 2014-08-26 17:28:41 · 390 阅读 · 0 评论 -
Unique Paths II
Follow up for "Unique Paths": Now consider if some obstacles are added to the grids. How many unique paths would there be? An obstacle and empty space is marked as 1 and 0 respectively in the原创 2014-09-10 22:36:52 · 273 阅读 · 0 评论 -
Minimum Path Sum
Given a m x n grid filled with non-negative numbers, find a path from top left to bottom right which minimizes the sum of all numbers along its path. Note: You can only move either down or right at原创 2014-09-11 07:59:08 · 208 阅读 · 0 评论 -
Add Two Numbers
You are given two linked lists representing two non-negative numbers. The digits are stored in reverse order and each of their nodes contain a single digit. Add the two numbers and return it as a link原创 2014-09-08 20:16:08 · 278 阅读 · 0 评论