摘要: 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.For example:Given the below binary tree andsum = 22, 5 / \ 4 8 / / \ 11 13 4 / \ ... 阅读全文
posted @ 2013-05-14 14:41 infinityu 阅读(167) 评论(0) 推荐(0) 编辑
摘要: You are given two linked lists representing two non-negative numbers. The digits are stored in reverse order and each of their nodes contain a single digit. Add the two numbers and return it as a linked list.Input:(2 -> 4 -> 3) + (5 -> 6 -> 4)Output:7 -> 0 -> 8/** * Definition for 阅读全文
posted @ 2013-05-14 14:18 infinityu 阅读(336) 评论(0) 推荐(0) 编辑
摘要: Reverse digits of an integer.Example1:x = 123, return 321Example2:x = -123, return -321 1 class Solution { 2 public: 3 int reverse(int x) { 4 // Start typing your C/C++ solution below 5 // DO NOT write int main() function 6 int sig = 1; 7 if(x<0){ 8 si... 阅读全文
posted @ 2013-05-14 12:43 infinityu 阅读(302) 评论(0) 推荐(0) 编辑
摘要: Given a linked list, remove thenthnode from the end of list and return its head.For example, Given linked list: 1->2->3->4->5, and n = 2. After removing the second node from the end, the linked list becomes 1->2->3->5.Note:Givennwill always be valid.Try to do this in one pass.解法 阅读全文
posted @ 2013-05-14 12:18 infinityu 阅读(312) 评论(0) 推荐(0) 编辑
摘要: Given a list, rotate the list to the right bykplaces, wherekis non-negative.For example:Given1->2->3->4->5->NULLandk=2,return4->5->1->2->3->NULL.解法:游标指针从头节点向后移动,当指向尾节点时,得到链表长度len,同时将链表头尾相连,接着游标再向后移动 k % len 步得到结果链表的尾节点。 1 /** 2 * Definition for singly-linked list. 3 * s 阅读全文
posted @ 2013-05-14 10:38 infinityu 阅读(770) 评论(0) 推荐(0) 编辑