摘要: 题目: Given an integer, write a function to determine if it is a power of three. Follow up:Could you do it without using any loop / recursion? 答案: 判断一个数 阅读全文
posted @ 2016-07-03 22:58 绵绵思远道 阅读(152) 评论(0) 推荐(0) 编辑
摘要: 问题: Write a program to find the node at which the intersection of two singly linked lists begins. For example, the following two linked lists: begin t 阅读全文
posted @ 2016-07-01 22:59 绵绵思远道 阅读(141) 评论(0) 推荐(0) 编辑
摘要: 问题: Given a non-negative integer num, repeatedly add all its digits until the result has only one digit. For example: Given num = 38, the process is l 阅读全文
posted @ 2016-07-01 22:40 绵绵思远道 阅读(108) 评论(0) 推荐(0) 编辑
摘要: 题目: Given an integer, write a function to determine if it is a power of two. 答案: 2的幂有两个特点: 1)大于0 2)二进制形式都是首位为1,其余位为0,因此n&(n-1)等于0 阅读全文
posted @ 2016-07-01 21:52 绵绵思远道 阅读(144) 评论(0) 推荐(0) 编辑
摘要: question: Given a singly linked list, determine if it is a palindrome. Follow up:Could you do it in O(n) time and O(1) space? answer: 思路:把前半部分的链表翻转,再分 阅读全文
posted @ 2016-06-29 12:54 绵绵思远道 阅读(142) 评论(0) 推荐(0) 编辑
摘要: 1.链表是一种与火车非常相似的数据结构,在链表里,我们叫火车头为表头,每节车厢就是链表的元素,车厢里载的人和物就是元素的数据域,连接车厢的部件就是元素的指针。从火车的结构我们可以发现链表的一个特点,元素之间前后依赖,串联而成。 2.性质: 元素相互依赖,串联而成(除了火车头,每节车厢都只链接到前一节 阅读全文
posted @ 2016-06-29 11:59 绵绵思远道 阅读(417) 评论(0) 推荐(0) 编辑
摘要: question: Remove all elements from a linked list of integers that have value val. ExampleGiven: 1 --> 2 --> 6 --> 3 --> 4 --> 5 --> 6, val = 6Return:  阅读全文
posted @ 2016-06-28 22:27 绵绵思远道 阅读(92) 评论(0) 推荐(0) 编辑
摘要: question: You are playing the following Nim Game with your friend: There is a heap of stones on the table, each time one of you take turns to remove 1 阅读全文
posted @ 2016-06-28 20:47 绵绵思远道 阅读(130) 评论(0) 推荐(0) 编辑
摘要: question: Reverse a singly linked list. answer: 使用三个指针遍历单链表,逐个链接点进行反转。 阅读全文
posted @ 2016-06-28 19:09 绵绵思远道 阅读(120) 评论(0) 推荐(0) 编辑
摘要: question: Write a function to delete a node (except the tail) in a singly linked list, given only access to that node. Supposed the linked list is 1 - 阅读全文
posted @ 2016-06-28 19:02 绵绵思远道 阅读(134) 评论(0) 推荐(0) 编辑