LeetCode
冬风噬雪
这个作者很懒,什么都没留下…
展开
-
LeetCode--1. Two Sum
1.Two SumGiven an array of integers, return indices of the two numbers such that they add up to a specific target.You may assume that each input would have exactly one solution.Example:原创 2016-12-04 20:24:31 · 180 阅读 · 0 评论 -
LeetCode--51. 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.Each s原创 2017-06-27 10:12:24 · 193 阅读 · 0 评论 -
LeetCode--104. Maximum Depth of Binary Tree
Given a binary tree, find its maximum depth.The maximum depth is the number of nodes along the longest path from the root node down to the farthest leaf node./** * Definition for a binary tree node.原创 2017-07-05 16:29:20 · 217 阅读 · 0 评论 -
LeetCode--47. 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], [2,1,1]]解决代码原创 2017-06-26 08:47:17 · 247 阅读 · 0 评论 -
LeetCode--100. Same Tree
Given two binary trees, write a function to check if they are equal or not.Two binary trees are considered equal if they are structurally identical and the nodes have the same value. 代码:/** * Definit原创 2017-07-04 10:34:49 · 201 阅读 · 0 评论 -
LeetCode--112. 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 = 2原创 2017-07-13 10:24:02 · 258 阅读 · 0 评论 -
LeetCode--77. 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],]解决代码:clas原创 2017-07-03 08:19:34 · 173 阅读 · 0 评论 -
LeetCode--52. N-Queens II
Follow up for N-Queens problem.Now, instead outputting board configurations, return the total number of distinct solutions.解决方法:class Solution {public: int totalNQueens(int n) { int count原创 2017-07-03 08:15:56 · 214 阅读 · 0 评论 -
LeetCode--216. Combination Sum III
Find all possible combinations of k numbers that add up to a number n, given that only numbers from 1 to 9 can be used and each combination should be a unique set of numbers.Example 1:Input: k = 3, n =原创 2017-07-03 08:02:21 · 167 阅读 · 0 评论 -
LeetCode--46. Permutations
Given a collection of distinct 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], [3,2,1]]解题代码:c原创 2017-06-21 19:49:55 · 175 阅读 · 0 评论 -
LeetCode--40. Combination Sum II
Given a collection of candidate numbers (C) and a target number (T), find all unique combinations in C where the candidate numbers sums to T.Each number in C may only be used once in the combination.No原创 2017-06-20 10:01:17 · 193 阅读 · 0 评论 -
Backtracking回溯法(又称DFS,递归)全解
回溯是啥用爬山来比喻回溯,好比从山脚下找一条爬上山顶的路,起初有好几条道可走,当选择一条道走到某处时,又有几条岔道可供选择,只能选择其中一条道往前走,若能这样子顺利爬上山顶则罢了,否则走到一条绝路上时,只好返回到最近的一个路口,重新选择另一条没走过的道往前走。如果该路口的所有路都走不通,只得从该路口继续回返。照此规则走下去,要么找到一条到达山顶的路,要么最终试过所有可能的道,无法到达山顶。 回溯是转载 2017-06-19 10:39:05 · 1305 阅读 · 0 评论 -
LeetCode--4. Median of Two Sorted Arrays
4. Median of Two Sorted ArraysThere are two sorted arrays nums1 and nums2 of size m and n respectively.Find the median of the two sorted arrays. The overall run time complexity should be O(log (m+n)).E原创 2017-04-27 08:05:51 · 227 阅读 · 0 评论 -
LeetCode--328.Odd Even Linked List
328. Odd Even Linked ListGiven a singly linked list, group all odd nodes together followed by the even nodes. Please note here we are talking about the node number and not the value in the n原创 2016-12-08 20:24:58 · 178 阅读 · 0 评论 -
LeetCode--2. Add Two Numbers
2. 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 and原创 2016-12-06 19:46:40 · 208 阅读 · 0 评论 -
LeetCode--111. 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.代码:/** * Definition for a binary tree node原创 2017-07-06 14:25:00 · 213 阅读 · 0 评论