![](https://img-blog.csdnimg.cn/20201014180756925.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
leetcode
文章平均质量分 76
martin_liang
这个作者很懒,什么都没留下…
展开
-
LeetCode Substring with Concatenation of All Words
转自出处Substring with Concatenation of All WordsYou are given a string, S, and a list of words, L, that are all of the same length. Find all starting indices of substring(s) in S that is a转载 2013-05-01 23:18:55 · 755 阅读 · 0 评论 -
LeetCode : Surrounded Regions
转自出处Given a 2D board containing 'X' and 'O', capture all regions surrounded by 'X'.A region is captured by flipping all 'O's into 'X's in that surrounded region .For example,X X转载 2013-04-30 10:32:51 · 701 阅读 · 0 评论 -
LeetCode Unique Binary Search Trees
// FindNumberOfBSTFromN.cpp : Defines the entry point for the console application.//#include "stdafx.h"#include #include using namespace std;int F(int);int f(int, int);int f(int i, int N){原创 2013-05-02 12:14:43 · 477 阅读 · 0 评论 -
leetcode: Generate Parentheses
Given n pairs of parentheses, write a function to generate all combinations of well-formed parentheses.For example, given n = 3, a solution set is:"((()))", "(()())", "(())()", "()(())", "()原创 2013-05-15 19:06:01 · 789 阅读 · 0 评论 -
leetcode: Path Sum II
Given a binary tree and a sum, find all root-to-leaf paths where each path's sum equals the given sum.For example:Given the below binary tree and sum = 22, 5 / \原创 2013-05-15 13:27:37 · 643 阅读 · 0 评论 -
leetcode: Partition List
/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; */class Solution {public: ListNode *pa原创 2013-05-02 23:58:50 · 498 阅读 · 0 评论 -
leetcode: 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原创 2013-05-16 23:40:59 · 648 阅读 · 0 评论 -
leetcode: Maximal Rectangle
class Solution {public: int maximalRectangle(vector > &matrix) { // Start typing your C/C++ solution below // DO NOT write int main() function int maxArea = 0; for (i原创 2013-05-04 00:02:20 · 665 阅读 · 0 评论 -
leetcode: Restore IP Addresses
Given a string containing only digits, restore it by returning all possible valid IP address combinations.For example:Given "25525511135",return ["255.255.11.135", "255.255.111.35"]. (Orde原创 2013-05-17 14:48:00 · 667 阅读 · 0 评论 -
leetcode: 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], [原创 2013-05-18 00:27:03 · 870 阅读 · 0 评论 -
leetcode: Remove Nth Node From End of List
/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; */class Solution {public: ListNode *re原创 2013-05-05 12:34:13 · 504 阅读 · 0 评论 -
leetcode: Simplify Path
Given an absolute path for a file (Unix-style), simplify it.For example,path = "/home/", => "/home"path = "/a/./b/../../c/", => "/c"class Solution {public: string simplifyPath(s原创 2013-05-18 23:34:42 · 772 阅读 · 1 评论 -
leetcode: 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 exa原创 2013-05-18 23:59:23 · 750 阅读 · 0 评论 -
leetcode: Subsets
Given a set of distinct integers, S, return all possible subsets.Note:Elements in a subset must be in non-descending order.The solution set must not contain duplicate subsets.For原创 2013-05-18 22:47:01 · 1122 阅读 · 0 评论 -
leetcode: Edit Distance
Given two words word1 and word2, find the minimum number of steps required to convert word1 to word2. (each operation is counted as 1 step.)You have the following 3 operations permitted on a w原创 2013-05-20 10:33:51 · 810 阅读 · 0 评论 -
leetcode: Merge k Sorted Lists
/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; */class Solution {public: ListNode *me原创 2013-05-06 18:06:39 · 460 阅读 · 0 评论 -
leetcode: 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原创 2013-05-06 21:06:45 · 1006 阅读 · 0 评论 -
leetcode: Sum Root to Leaf Numbers
Given a binary tree containing digits from 0-9 only, each root-to-leaf path could represent a number.An example is the root-to-leaf path 1->2->3 which represents the number 123.Find the to原创 2013-05-07 00:25:09 · 485 阅读 · 0 评论 -
leetcode: Longest Valid Parentheses
// Longest ().cpp : Defines the entry point for the console application.//#include "stdafx.h"#include #include #include using namespace std;struct nodeStruct{ int startPos; int end原创 2013-05-06 16:34:18 · 579 阅读 · 0 评论 -
leetcode: Balanced Binary Tree
Given a binary tree, determine if it is height-balanced.For this problem, a height-balanced binary tree is defined as a binary tree in which the depth of the two subtrees ofevery node never diff原创 2013-05-20 13:42:19 · 1082 阅读 · 0 评论 -
leetcode: Remove Duplicates from Sorted List
Given a sorted linked list, delete all duplicates such that each element appear only once.For example,Given 1->1->2, return 1->2.Given 1->1->2->3->3, return 1->2->3./** * Defini原创 2013-05-07 17:11:11 · 450 阅读 · 0 评论 -
leetcode: Minimum Depth of Binary Tree
Given a binary tree, find its minimum depth.The minimum depth is the number of nodes along the shortest path from the root node down to the nearest leaf node.» Solve this problem/** * D原创 2013-05-07 20:02:23 · 519 阅读 · 0 评论 -
leetcode:Gray Code
The gray code is a binary numeral system where two successive values differ in only one bit.Given a non-negative integer n representing the total number of bits in the code, print the sequence o原创 2013-05-08 11:00:50 · 756 阅读 · 0 评论 -
leetcode: Length of Last Word
Given a string s consists of upper/lower-case alphabets and empty space characters ' ', return the length of last word in the string.If the last word does not exist, return 0.Note: A word is原创 2013-05-08 01:40:03 · 669 阅读 · 0 评论 -
leetcode: Search for a Range
Given a sorted array of integers, find the starting and ending position of a given target value.Your algorithm's runtime complexity must be in the order of O(log n).If the target is not found原创 2013-05-21 22:35:45 · 464 阅读 · 0 评论 -
leetcode: Decode ways
A message containing letters from A-Z is being encoded to numbers using the following mapping:'A' -> 1'B' -> 2...'Z' -> 26Given an encoded message containing digits, determine the total nu原创 2013-05-08 23:40:37 · 440 阅读 · 0 评论 -
leetcode: Jump Game II
Given an array of non-negative integers, you are initially positioned at the first index of the array.Each element in the array represents your maximum jump length at that position.Your goal i原创 2013-05-09 00:32:35 · 1419 阅读 · 0 评论 -
leetcode: Palindrome Number
Determine whether an integer is a palindrome. Do this without extra space.class Solution {public: bool isPalindrome(int x) { // Start typing your C/C++ solution below // DO原创 2013-05-24 11:27:56 · 531 阅读 · 0 评论 -
leetcode: Swap Nodes in Pairs
Given a linked list, swap every two adjacent nodes and return its head.For example,Given 1->2->3->4, you should return the list as 2->1->4->3.Your algorithm should use only constant原创 2013-05-24 10:51:00 · 462 阅读 · 0 评论 -
leetcode Pow(x, n)
Implement pow(x, n).下面的算法,满足small judge, 但是 large judege超出时间限制class Solution {public: double pow(double x, int n) { // Start typing your C/C++ solution below // DO NOT w原创 2013-05-10 12:32:57 · 1236 阅读 · 0 评论 -
leetcode: Remove Element
Given an array and a value, remove all instances of that value in place and return the new length.The order of elements can be changed. It doesn't matter what you leave beyond the new length.原创 2013-05-10 16:48:32 · 488 阅读 · 0 评论 -
leetcode: Binary Tree Maximum Path Sum
Given a binary tree, find the maximum path sum.The path may start and end at any node in the tree.For example:Given the below binary tree, 1 / \ 2 3Return 6.原创 2013-05-10 18:26:41 · 469 阅读 · 0 评论 -
leetcode: Convert Sorted Array to Binary Search Tree
Given an array where elements are sorted in ascending order, convert it to a height balanced BST./** * Definition for binary tree * struct TreeNode { * int val; * TreeNode *left; *原创 2013-05-24 18:35:52 · 638 阅读 · 0 评论 -
leetcode: 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 equal tox.You should preserve the original relative order of the nodes in each o原创 2013-05-11 00:41:39 · 468 阅读 · 0 评论 -
leetcode: 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原创 2013-05-24 18:08:21 · 795 阅读 · 0 评论 -
leetcode: Maximal Rectangle
Largest Rectangle in HistogramApr 23 '121499 / 4823Given n non-negative integers representing the histogram's bar height where the width of each bar is 1, find the area of largest rectangl原创 2013-05-11 22:39:03 · 879 阅读 · 0 评论 -
leetcode: Spiral Matrix
Given a matrix of m x n elements (m rows, n columns), return all elements of the matrix in spiral order.For example,Given the following matrix:[ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ]]原创 2013-05-28 00:47:01 · 619 阅读 · 0 评论 -
leetcode: 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 the nodes of the first two lists./** * Definition for singly-linked list. * struct L原创 2013-05-13 23:56:03 · 936 阅读 · 0 评论 -
leetcode: Longest Common Prefix
Write a function to find the longest common prefix string amongst an array of strings.#define MAX_LEN 0xFFFFclass Solution {public: string longestCommonPrefix(vector &strs) { /原创 2013-05-14 00:16:16 · 679 阅读 · 0 评论 -
leetcode: Combination Sum
Given a set of candidate numbers (C) and a target number (T), find all unique combinations in C where the candidate numbers sums to T.The same repeated number may be chosen from C unlimited原创 2013-05-28 12:45:19 · 552 阅读 · 0 评论