![](https://img-blog.csdnimg.cn/20201014180756927.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
LeetCode
文章平均质量分 72
wyc1230
这个作者很懒,什么都没留下…
展开
-
LeetCode: Combination Sum
#include#include#includeusing namespace::std;class Solution {public: vector > combinationSum(vector & candidates, int target) { map > > result; for(int i = 0; i <= target; i++) {原创 2012-09-30 11:35:34 · 525 阅读 · 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 / \原创 2014-09-25 14:20:15 · 363 阅读 · 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 of every node never diffe原创 2014-09-26 00:48:03 · 305 阅读 · 0 评论 -
LeetCode: Find Minimum in Rotated Sorted Array II
Follow up for "Find Minimum in Rotated Sorted Array":What if duplicates are allowed?Would this affect the run-time complexity? How and why?Suppose a sorted array is rotated at some pivot unk原创 2014-10-23 14:16:48 · 356 阅读 · 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"click to show corner cases.Corner Cases:Did原创 2014-10-31 15:00:03 · 340 阅读 · 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],]原创 2014-11-04 14:27:20 · 338 阅读 · 0 评论 -
LeetCode: Sort Colors
Given an array with n objects colored red, white or blue, sort them so that objects of the same color are adjacent, with the colors in the order red, white and blue.Here, we will use the integers原创 2014-10-28 14:31:13 · 370 阅读 · 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 space.原创 2012-02-16 12:36:54 · 1619 阅读 · 0 评论 -
LeetCode: 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.class Solution {public: st原创 2015-01-16 13:23:38 · 378 阅读 · 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.c原创 2012-02-29 02:53:13 · 1055 阅读 · 0 评论 -
LeetCode: Compare Version Numbers
Compare two version numbers version1 and version2.If version1 > version2 return 1, if version1 version2 return -1, otherwise return 0.You may assume that the version strings are non-empty and co原创 2015-03-02 15:33:26 · 464 阅读 · 0 评论 -
LeetCode: Excel Sheet Column Title
Given a positive integer, return its corresponding column title as appear in an Excel sheet.For example: 1 -> A 2 -> B 3 -> C ... 26 -> Z 27 -> AA 28 -> AB class Sol原创 2015-03-02 13:00:54 · 370 阅读 · 0 评论 -
LeetCode: 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-10-29 14:47:47 · 346 阅读 · 0 评论 -
LeetCode: 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-10-28 15:08:30 · 301 阅读 · 0 评论 -
LeetCode: 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].class Sol原创 2015-01-05 15:07:08 · 321 阅读 · 0 评论 -
LeetCode: Pow(x, n)
Implement pow(x, n).class Solution {public: double pow(double x, int n) { double result = helper(x, std::abs(n)); return n > 0 ? result : 1/result; } double hel原创 2014-12-19 14:47:07 · 327 阅读 · 0 评论 -
LeetCode: Subsets II
Given a collection of integers that might contain duplicates, S, return all possible subsets.Note:Elements in a subset must be in non-descending order.The solution set must not contain dupli原创 2014-10-13 13:06:58 · 365 阅读 · 0 评论 -
LeetCode: Anagrams
Given an array of strings, return all groups of strings that are anagrams.Note: All inputs will be in lower-case.#include#include#include#includeusing namespace::std;class Solution {pu原创 2012-03-21 13:25:25 · 2580 阅读 · 0 评论 -
LeetCode: Rotate Image
You are given an n x n 2D matrix representing an image.Rotate the image by 90 degrees (clockwise).Follow up:Could you do this in-place?class Solution {public: void rotate(vector >原创 2015-01-05 14:14:20 · 340 阅读 · 0 评论 -
LeetCode: Search Insert Position
Given a sorted array and a target value, return the index if the target is found. If not, return the index where it would be if it were inserted in order.You may assume no duplicates in the array.原创 2015-01-17 10:47:19 · 381 阅读 · 0 评论 -
LeetCode: Binary Tree Preorder Traversal
Given a binary tree, return the preorder traversal of its nodes' values.For example:Given binary tree {1,#,2,3}, 1 \ 2 / 3return [1,2,3].Note: Recursive soluti原创 2014-08-12 13:15:27 · 345 阅读 · 0 评论 -
LeetCode: Integer to Roman
Given an integer, convert it to a roman numeral.Input is guaranteed to be within the range from 1 to 3999.class Solution {public: string intToRoman(int num) { string result;原创 2015-01-23 15:43:12 · 331 阅读 · 0 评论 -
LeetCode: 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 7 0 1 2).You are given a target value to search. If found in the array retur原创 2014-10-19 14:20:45 · 324 阅读 · 0 评论 -
LeetCode: Sqrt(x)
Implement int sqrt(int x).Compute and return the square root of x.原创 2014-11-01 01:40:21 · 354 阅读 · 0 评论 -
LeetCode: Reorder List
Given a singly linked list L: L0→L1→…→Ln-1→Ln,reorder it to: L0→Ln→L1→Ln-1→L2→Ln-2→…You must do this in-place without altering the nodes' values.For example,Given {1,2,3,4}, reorder it t原创 2014-08-12 14:25:05 · 358 阅读 · 0 评论 -
LeetCode: Linked List Cycle II
Given a linked list, return the node where the cycle begins. If there is no cycle, return null.Follow up:Can you solve it without using extra space?/** * Definition for singly-linked list.原创 2014-08-13 04:58:54 · 332 阅读 · 0 评论 -
LeetCode: Single Number
Given an array of integers, every element appears twice except for one. Find that single one.Note:Your algorithm should have a linear runtime complexity. Could you implement it without using e原创 2014-08-26 11:44:56 · 314 阅读 · 0 评论 -
LeetCode: Clone Graph
Clone an undirected graph. Each node in the graph contains a label and a list of its neighbors.OJ's undirected graph serialization:Nodes are labeled uniquely.We use # as a separator for ea原创 2014-08-27 22:40:53 · 341 阅读 · 0 评论 -
LeetCode: 3 Sum 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原创 2012-03-21 03:15:54 · 2746 阅读 · 0 评论 -
LeetCode: 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","原创 2014-08-29 12:53:49 · 382 阅读 · 0 评论 -
LeetCode: Climbing Stairs
#include#include#includeusing namespace::std;class Solution {public: //iteration int climbStairs(int n) { if(n == 0 || n == 1) return 1; int steps_n_2 = 1;原创 2012-09-26 12:34:23 · 317 阅读 · 0 评论 -
LeetCode: Single Number II
Given an array of integers, every element appears three times except for one. Find that single one.Note:Your algorithm should have a linear runtime complexity. Could you implement it without u原创 2014-08-26 12:07:51 · 311 阅读 · 0 评论 -
LeetCode: Linked List Cycle
Given a linked list, determine if it has a cycle in it.Follow up:Can you solve it without using extra space?原创 2014-08-13 04:25:29 · 425 阅读 · 0 评论 -
LeetCode: Unique Paths
A robot is located at the top-left corner of a m x n grid (marked 'Start' in the diagram below).The robot can only move either down or right at any point in time. The robot is trying to reach the原创 2014-11-07 08:02:26 · 357 阅读 · 0 评论 -
LeetCode: Add Two Numbers
Add Two NumbersYou 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原创 2012-01-18 14:13:02 · 1194 阅读 · 0 评论 -
LeetCode: 3Sum
Given an array S of n integers, are there elements a, b, c in S such that a + b + c = 0? Find all unique triplets in the array which gives the sum of zero.Note:Elements in a triplet原创 2012-03-21 02:49:01 · 5655 阅读 · 4 评论 -
LeetCode: 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-11-07 07:48:35 · 382 阅读 · 0 评论 -
LeetCode: 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 "()",原创 2015-01-18 06:12:11 · 312 阅读 · 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 word:原创 2014-11-02 12:54:49 · 342 阅读 · 0 评论 -
LeetCode: Binary Search Tree Iterator
Implement an iterator over a binary search tree (BST). Your iterator will be initialized with the root node of a BST.Calling next() will return the next smallest number in the BST.Note: next()原创 2015-03-07 10:46:24 · 368 阅读 · 0 评论