LeetCode
文章平均质量分 74
自自然卷
这个作者很懒,什么都没留下…
展开
-
89. Gray Code M
LeetCode 89 GrayCode M原创 2016-09-06 20:40:31 · 222 阅读 · 0 评论 -
15. 3Sum M
原题: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: The solution set must no原创 2016-09-25 21:55:25 · 199 阅读 · 0 评论 -
N-Queens II
原题:Follow up for N-Queens problem.Now, instead outputting board configurations, return the total number of distinct solutions.回溯法代码:public class Solution { boolean able_place(boole原创 2016-11-16 13:34:40 · 248 阅读 · 0 评论 -
Word Ladder II
Given two words (beginWord and endWord), and a dictionary's word list, find all shortest transformation sequence(s) from beginWord toendWord, such that:Only one letter can be changed at a timeEach原创 2016-11-12 23:04:22 · 340 阅读 · 0 评论 -
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原创 2016-11-16 15:30:14 · 321 阅读 · 0 评论 -
Can I Win
原题:In the "100 game," two players take turns adding, to a running total, any integer from 1..10. The player who first causes the running total to reach or exceed 100 wins.What if we change the原创 2016-12-11 15:43:29 · 415 阅读 · 0 评论 -
Basic Calculator
Implement a basic calculator to evaluate a simple expression string.The expression string may contain open ( and closing parentheses ), the plus + or minus sign -, non-negative integers and em原创 2016-11-10 21:39:30 · 314 阅读 · 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".Update (2015-02-12):For C programmers: Try to solve it in-place in原创 2016-11-23 11:38:20 · 317 阅读 · 0 评论 -
Odd Even Linked List
Given 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 nodes.You should try to do it in原创 2016-12-07 09:39:33 · 339 阅读 · 0 评论 -
Implement strStr()
Implement strStr().Returns the index of the first occurrence of needle in haystack, or -1 if needle is not part of haystack.用的KMP算法,时间复杂度O(n+m),建立Next数组的时间复杂度需要仔细观察才能计算出来,参考《算法导论》KMP算法细说起来比较麻烦原创 2016-11-27 10:35:33 · 256 阅读 · 0 评论 -
Majority Element
算法证明见论文,论文节选5.2 The Algorithm Imagine a convention center filled with delegates (Le., voters) each carrying a placard proclaiming the name of his candidate. Suppose a floor fight ensues and delega原创 2017-03-24 15:39:37 · 382 阅读 · 0 评论 -
Binary Tree Inorder Traversal
中序遍历一个二叉树Given a binary tree, return the inorder traversal of its nodes' values.For example:Given binary tree [1,null,2,3], 1 \ 2 / 3return [1,3,2].Note:原创 2016-11-05 13:12:21 · 245 阅读 · 0 评论 -
Construct Binary Tree from Preorder and Inorder Traversal
Given preorder and inorder traversal of a tree, construct the binary tree.Note:You may assume that duplicates do not exist in the tree.开始还想着有重复怎么办,后来发现题目给了没有重复数字,如果有重复数字那树可能不唯一,但是假如只有一两个重复数字树还原创 2016-11-05 19:51:43 · 295 阅读 · 0 评论 -
Add Binary
主要拿来练C语言语法,代码不是很好看Given two binary strings, return their sum (also a binary string).For example,a = "11"b = "1"Return "100".char* addBinary(char* a, char* b) { char *pa = a; ch原创 2016-10-23 16:45:01 · 226 阅读 · 0 评论 -
85. Maximal Rectangle H
85. Maximal Rectangle原创 2016-09-15 21:28:27 · 253 阅读 · 0 评论 -
84. Largest Rectangle in Histogram H
Largest Rectangle in Histogram原创 2016-09-13 21:40:46 · 308 阅读 · 0 评论 -
33. Search in Rotated Sorted Array H
Search in Rotated Sorted Array原创 2016-09-17 10:29:59 · 295 阅读 · 0 评论 -
136. Single Number E
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原创 2016-09-06 20:47:51 · 270 阅读 · 0 评论 -
344. Reverse String E
Write a function that takes a string as input and returns the string reversed.Example:Given s = "hello", return "olleh".C版char* reverseString(char* s) { int i = -1; int len;原创 2016-09-06 20:50:34 · 237 阅读 · 0 评论 -
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 of you take turns to remove 1 to 3 stones. The one who removes the last stone will be the原创 2016-09-06 20:52:43 · 280 阅读 · 0 评论 -
2. Add Two Numbers M
LeetCode 2. Add Two Numbers M原创 2016-09-06 20:45:07 · 241 阅读 · 0 评论 -
167. Two Sum II - Input array is sorted M
167. Two Sum II - Input array is sorted M原创 2016-09-07 21:16:11 · 229 阅读 · 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原创 2016-10-21 20:24:30 · 216 阅读 · 0 评论 -
Find the Difference
iven two strings s and t which consist of only lowercase letters.String t is generated by random shuffling string s and then add one more letter at a random position.Find the letter that was a原创 2016-10-23 16:41:18 · 240 阅读 · 0 评论 -
Wildcard Matching & Regular Expression Matching & KMP
觉得Wildcard Matching & Regular Expression Matching & KMP都是字符串匹配问题,所以想把它们放一起方法有动态规划、回溯、有限自动机一、Wildcard Matching:Implement wildcard pattern matching with support for '?' and '*'.'?' Matches原创 2016-10-19 16:09:08 · 515 阅读 · 0 评论