随笔分类 - LeetCode
leetcode 的解题记录
摘要:题目:Determine whether an integer is a palindrome. Do this without extra space.解题思路:循环取得首位和末尾,然后比较。解题心得:关于整数的处理有几个 运算需要熟记:一个整数:%10 得个位 , %100 的后两位 就是个位和...
阅读全文
摘要:题目: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...
阅读全文
摘要:题目:(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...
阅读全文
摘要:题目: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...
阅读全文
摘要:题目(Tree DFS)Given a binary tree, flatten it to a linked list in-place.For example,Given 1 / \ 2 5 / \ \ 3 4 6The...
阅读全文
摘要:题目:(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 ...
阅读全文
摘要:题目:(DP)Givenn, generate all structurally uniqueBST's(binary search trees) that store values 1...n.For example,Givenn= 3, your program should return al...
阅读全文
摘要:题目:(Backtrancing)Givennpairs of parentheses, write a function to generate all combinations of well-formed parentheses.For example, givenn= 3, a soluti...
阅读全文
摘要:题目:(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...
阅读全文
摘要:题目: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...
阅读全文
摘要:题目:(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...
阅读全文
摘要:题目:(DP, Backtracing)Given a stringsand a dictionary of wordsdict, add spaces insto construct a sentence where each word is a valid dictionary word.Ret...
阅读全文
摘要:题目:Given two words (startandend), and a dictionary, find all shortest transformation sequence(s) fromstarttoend, such that:Only one letter can be chan...
阅读全文
摘要:题目:(Tree ,Stack)Given a binary tree, return thepostordertraversal of its nodes' values.For example:Given binary tree{1,#,2,3}, 1 \ 2 / 3...
阅读全文
摘要:题目:(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 ...
阅读全文
摘要:题目:(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...
阅读全文
摘要:题目:(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 ...
阅读全文
摘要:题目:(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 ...
阅读全文
摘要:题目:(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...
阅读全文
摘要:题目:(Math)Given an integern, return the number of trailing zeroes inn!.Note:Your solution should be in logarithmic time complexity.题解:首先列几个例子找一找规律。然后发现...
阅读全文
浙公网安备 33010602011771号