摘要: Given a binary tree, find the lowest common ancestor (LCA) of two given nodes in the tree. According to the definition of LCA on Wikipedia: “The lowes 阅读全文
posted @ 2016-08-07 16:53 西小贝 阅读(120) 评论(0) 推荐(0)
摘要: 题意:给出分子和分母,用字符串表示结果,循环的部分用“()”括起来。 思路: 模拟笔算, 最初根据1/99的情况,设想用path记录余数相同时的间隔步长,但只能用于处理(00..0n)的情况,其中n为[1,9]; 后来采取网上看到用map记录<余数,出现位置>的想法。 通过判断map中key是否重复 阅读全文
posted @ 2016-07-24 20:07 西小贝 阅读(218) 评论(0) 推荐(0)
摘要: Given a singly linked list L: 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 阅读全文
posted @ 2016-05-09 21:41 西小贝 阅读(184) 评论(0) 推荐(0)
摘要: Given a linked list, return the node where the cycle begins. If there is no cycle, return null. Note: Do not modify the linked list. note: 开始时,两指针都指向h 阅读全文
posted @ 2016-05-09 19:01 西小贝 阅读(158) 评论(0) 推荐(0)
摘要: Given a binary tree, determine if it is a valid binary search tree (BST).Assume a BST is defined as follows:The left subtree of a node contains only n... 阅读全文
posted @ 2016-01-07 23:28 西小贝 阅读(125) 评论(0) 推荐(0)
摘要: Given a binary tree, return theinordertraversal of its nodes' values.For example:Given binary tree{1,#,2,3}, 1 \ 2 / 3return[1,3,2].Note... 阅读全文
posted @ 2016-01-06 16:10 西小贝 阅读(138) 评论(0) 推荐(0)
摘要: 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->2->5->NULL.No... 阅读全文
posted @ 2016-01-06 16:09 西小贝 阅读(186) 评论(0) 推荐(0)
摘要: Given a string containing only digits, restore it by returning all possible valid IP address combinations.For example:Given"25525511135",return["255.2... 阅读全文
posted @ 2016-01-06 16:09 西小贝 阅读(147) 评论(0) 推荐(0)
摘要: Given a collection of integers that might contain duplicates,nums, return all possible subsets.Note:Elements in a subset must be in non-descending ord... 阅读全文
posted @ 2016-01-06 16:07 西小贝 阅读(182) 评论(0) 推荐(0)
摘要: A message containing letters fromA-Zis being encoded to numbers using the following mapping:'A' -> 1'B' -> 2...'Z' -> 26Given an encoded message conta... 阅读全文
posted @ 2016-01-06 16:07 西小贝 阅读(199) 评论(0) 推荐(0)