11 2014 档案
摘要:Given a binary tree and a sum, find all root-to-leaf paths where each path's sum equals the given sum.For example:Given the below binary tree andsum =...
阅读全文
摘要: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.Fo...
阅读全文
摘要:Merge two sorted linked lists and return it as a new list. The new list should be made by splicing together the nodes of the first two lists.注意写出鲁棒性的代...
阅读全文
摘要:Implement pow(x,n).思路:像string to integer一样。考虑的细节较多。 1.测试用例要考虑基数和指数都为正数、负数和零的情况。 2.注意0的0次方在数学上没有意义。 3.考虑底数为0且指数为负数的处理方法。可以有返回值、全局变量和异常。这里使用全局变量区别...
阅读全文
摘要:You are climbing a stair case. It takesnsteps to reach to the top.Each time you can either climb 1 or 2 steps. In how many distinct ways can you climb...
阅读全文
摘要:Follow up for "Search in Rotated Sorted Array":What ifduplicatesare allowed?Would this affect the run-time complexity? How and why?Write a function to...
阅读全文
摘要: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).You are given a target value t...
阅读全文
摘要:Given two sorted integer arrays A and B, merge B into A as one sorted array.Note:You may assume that A has enough space (size that is greater or equal...
阅读全文
摘要:Write a function to find the longest common prefix string amongst an array of strings.思路:每个字符串都与第0个字符串比较,设置一个变量,记录每个字符串与第0个字符串不匹配位置的最小值 时间复杂度O(n1+n2...
阅读全文
摘要:Given two binary strings, return their sum (also a binary string).For example,a ="11"b ="1"Return"100"思路:时间复杂度O(n), 空间复杂度O(1) 1 class Solution { 2 pub...
阅读全文
摘要:Implementatoito convert a string to an integer.Hint:Carefully consider all possible input cases. If you want a challenge, please do not see below and ...
阅读全文
摘要:Given a string, determine if it is a palindrome, considering only alphanumericcharacters and ignoring cases.For example,"A man, a plan, a canal: Panam...
阅读全文
摘要:Given a singlylinked 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 examp...
阅读全文
摘要:Given a linked list, return the node where the cycle begins. If there is no cycle, returnnull.Follow up:Can you solve it without using extra space?思路:...
阅读全文
摘要:Given a linked list, determine if it has a cycle in it.Follow up:Can you solve it without using extra space?思路:快慢指针的应用。快慢指针指的是移动的步长,即每次向前移动的快慢。例如可以让快指...
阅读全文
摘要:A linked list is given such that each node contains an additional random pointer which could point to any node in the list or null.Return a deep copy ...
阅读全文
浙公网安备 33010602011771号