随笔分类 - Leetcode Solutions
includ leetcode, lintcode and other solutions.
摘要:Given a binary tree struct TreeLinkNode { TreeLinkNode *left; TreeLinkNode *right; TreeLinkNode *next; }Populate each next pointe...
阅读全文
摘要:题目:Design and implement a data structure for Least Recently Used (LRU) cache. It should support the following operations:getandset.get(key)- Get the v...
阅读全文
摘要:Given an array of integers, find two numbers such that they add up to a specific target number.The function twoSum should return indices of the two nu...
阅读全文
摘要:Write a program to find the node at which the intersection of two singly linked lists begins.For example, the following two linked lists:A: a...
阅读全文
摘要:Implement pow(x,n).思路:这个题虽然简单,但是一开始我也没做利索。我思路不简洁的地方有:1.首先我想到的是符号问题,因此我用了flag来标记x的正负。可实际并不需要。2.其次是n得正负问题,我们不用先计算后取倒数,而是直接取倒数在运算。 1 public double myPow(...
阅读全文
摘要:Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center).For example, this binary tree is symmetric: 1 / \ ...
阅读全文
摘要:Given a binary search tree (BST), find the lowest common ancestor (LCA) of two given nodes in the BST.According to thedefinition of LCA on Wikipedia: ...
阅读全文
摘要:Validate if a given string is numeric.Some examples:"0" => true" 0.1 " => true"abc" => false"1 a" => false"2e10" => trueNote: It is intended for the p...
阅读全文
摘要:题目:Given a singly linked listL: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 e...
阅读全文
摘要:题目:All DNA is composed of a series of nucleotides abbreviated as A, C, G, and T, for example: "ACGAATTCCG". When studying DNA, it is sometimes useful ...
阅读全文
摘要:题目:Given a digit string, return all possible letter combinations that the number could represent.A mapping of digit to letters (just like on the telep...
阅读全文
摘要:题目:Given an array of strings, return all groups of strings that are anagrams.Note: All inputs will be in lower-case.思路:面试过更简单的形式,判断两个string是否是anagram。...
阅读全文
摘要:题目:Given a 2D board containing'X'and'O', capture all regions surrounded by'X'.A region is captured by flipping all'O's into'X's in that surrounded reg...
阅读全文
摘要:题目:Write an algorithm to determine if a number is "happy".A happy number is a number defined by the following process: Starting with any positive inte...
阅读全文
摘要:题目:Then-queens puzzle is the problem of placingnqueens on ann×nchessboard such that no two queens attack each other.Given an integern, return all dist...
阅读全文
摘要:题目:Given a strings, partitionssuch that every substring of the partition is a palindrome.Return all possible palindrome partitioning ofs.For example, ...
阅读全文
摘要:题目:Given a linked list, determine if it has a cycle in it.Follow up:Can you solve it without using extra space?思路:We can use two pointers: walker and ...
阅读全文
摘要:题目:Given two integers representing the numerator and denominator of a fraction, return the fraction in string format.If the fractional part is repeati...
阅读全文
摘要:题目:Given a 2d grid map of'1's (land) and'0's (water), count the number of islands. An island is surrounded by water and is formed by connecting adjace...
阅读全文
摘要:题目:Given a range [m, n] where 0 >>= 1; 8 n >>>= 1; 9 count++;10 }11 return m <<= count;12 }
阅读全文
浙公网安备 33010602011771号