随笔分类 -  LeetCode

leetcode 的解题记录
摘要:题目:Determine whether an integer is a palindrome. Do this without extra space.解题思路:循环取得首位和末尾,然后比较。解题心得:关于整数的处理有几个 运算需要熟记:一个整数:%10 得个位 , %100 的后两位 就是个位和... 阅读全文
posted @ 2015-08-19 09:47 fengmang 阅读(98) 评论(0) 推荐(0)
摘要:题目:Suppose a sorted array is rotated at some pivot unknown to you beforehand.(i.e.,0 1 2 4 5 6 7might become4 5 6 7 0 1 2).Find the minimum element.Yo... 阅读全文
posted @ 2015-08-19 08:10 fengmang 阅读(185) 评论(0) 推荐(0)
摘要:题目:(Backtrancing)Given a 2D board and a word, find if the word exists in the grid.The word can be constructed from letters of sequentially adjacent ce... 阅读全文
posted @ 2015-01-08 22:48 fengmang 阅读(180) 评论(0) 推荐(0)
摘要:题目:Given preorder and inorder traversal of a tree, construct the binary tree.Note:You may assume that duplicates do not exist in the tree./** * Defini... 阅读全文
posted @ 2015-01-06 03:00 fengmang 阅读(124) 评论(0) 推荐(0)
摘要:题目(Tree DFS)Given a binary tree, flatten it to a linked list in-place.For example,Given 1 / \ 2 5 / \ \ 3 4 6The... 阅读全文
posted @ 2015-01-06 02:37 fengmang 阅读(150) 评论(0) 推荐(0)
摘要:题目:(Tree ,DFS)Two elements of a binary search tree (BST) are swapped by mistake.Recover the tree without changing its structure.Note:A solution using ... 阅读全文
posted @ 2015-01-06 01:39 fengmang 阅读(133) 评论(0) 推荐(0)
摘要:题目:(DP)Givenn, generate all structurally uniqueBST's(binary search trees) that store values 1...n.For example,Givenn= 3, your program should return al... 阅读全文
posted @ 2015-01-06 00:09 fengmang 阅读(194) 评论(0) 推荐(0)
摘要:题目:(Backtrancing)Givennpairs of parentheses, write a function to generate all combinations of well-formed parentheses.For example, givenn= 3, a soluti... 阅读全文
posted @ 2015-01-03 03:28 fengmang 阅读(79) 评论(0) 推荐(0)
摘要:题目:(DP)Given a stringSand a stringT, count the number of distinct subsequences ofTinS.A subsequence of a string is a new string which is formed from t... 阅读全文
posted @ 2015-01-02 10:13 fengmang 阅读(159) 评论(0) 推荐(0)
摘要:题目:Given a strings1, we may represent it as a binary tree by partitioning it to two non-empty substrings recursively.Below is one possible representat... 阅读全文
posted @ 2015-01-02 04:06 fengmang 阅读(127) 评论(0) 推荐(0)
摘要:题目:(DP)Givenn, how many structurally uniqueBST's(binary search trees) that store values 1...n?For example,Givenn= 3, there are a total of 5 unique BST... 阅读全文
posted @ 2015-01-02 03:43 fengmang 阅读(186) 评论(0) 推荐(0)
摘要:题目:(DP, Backtracing)Given a stringsand a dictionary of wordsdict, add spaces insto construct a sentence where each word is a valid dictionary word.Ret... 阅读全文
posted @ 2015-01-02 01:53 fengmang 阅读(266) 评论(0) 推荐(0)
摘要:题目:Given two words (startandend), and a dictionary, find all shortest transformation sequence(s) fromstarttoend, such that:Only one letter can be chan... 阅读全文
posted @ 2015-01-01 10:44 fengmang 阅读(189) 评论(0) 推荐(0)
摘要:题目:(Tree ,Stack)Given a binary tree, return thepostordertraversal of its nodes' values.For example:Given binary tree{1,#,2,3}, 1 \ 2 / 3... 阅读全文
posted @ 2015-01-01 06:51 fengmang 阅读(108) 评论(0) 推荐(0)
摘要:题目:(Stack)Givennnon-negative integers representing the histogram's bar height where the width of each bar is 1, find the area of largest rectangle in ... 阅读全文
posted @ 2015-01-01 04:39 fengmang 阅读(146) 评论(0) 推荐(0)
摘要:题目:(LinkedList)Reverse a linked list from positionmton. Do it in-place and in one-pass.For example:Given1->2->3->4->5->NULL,m= 2 andn= 4,return1->4->3... 阅读全文
posted @ 2015-01-01 01:01 fengmang 阅读(91) 评论(0) 推荐(0)
摘要:题目:(Tree Stack)Implement an iterator over a binary search tree (BST). Your iterator will be initialized with the root node of a BST.Callingnext()will ... 阅读全文
posted @ 2014-12-31 22:59 fengmang 阅读(102) 评论(0) 推荐(0)
摘要:题目:(HashTable Two Point String)Given a string S and a string T, find the minimum window in S which will contain all the characters in T in complexity ... 阅读全文
posted @ 2014-12-31 06:54 fengmang 阅读(130) 评论(0) 推荐(0)
摘要:题目:(HashTable,Two Point)You 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... 阅读全文
posted @ 2014-12-31 03:54 fengmang 阅读(147) 评论(0) 推荐(0)
摘要:题目:(Math)Given an integern, return the number of trailing zeroes inn!.Note:Your solution should be in logarithmic time complexity.题解:首先列几个例子找一找规律。然后发现... 阅读全文
posted @ 2014-12-30 22:58 fengmang 阅读(218) 评论(0) 推荐(0)