摘要: 在一组数的编码中,若任意两个相邻的代码只有一位二进制数不同, 则称这种编码为格雷码(Gray Code),请编写一个函数,使用递归的方法生成N位的格雷码。 给定一个整数n,请返回n位的格雷码,顺序为从0开始。 Example: 1 : 0 , 1 2: 00 01 11 10 3: 000 001 阅读全文
posted @ 2016-03-27 09:53 YuriFLAG 阅读(274) 评论(0) 推荐(0)
摘要: Follow up for "Unique Paths": Now consider if some obstacles are added to the grids. How many unique paths would there be? An obstacle and empty space 阅读全文
posted @ 2016-03-27 09:00 YuriFLAG 阅读(177) 评论(0) 推荐(0)
摘要: A robot is located at the top-left corner of a m x n grid (marked 'Start' in the diagram below). The robot can only move either down or right at any p 阅读全文
posted @ 2016-03-27 08:48 YuriFLAG 阅读(132) 评论(0) 推荐(0)
摘要: Given a singly linked list, group all odd nodes together followed by the even nodes. Please note here we are talking about the node number and not the 阅读全文
posted @ 2016-03-26 09:51 YuriFLAG 阅读(174) 评论(0) 推荐(0)
摘要: Find the nth to last element of a singly linked list. The minimum number of nodes in list is n. Example Given a List 3->2->1->5->null and n = 2, retur 阅读全文
posted @ 2016-03-26 09:12 YuriFLAG 阅读(195) 评论(0) 推荐(0)
摘要: Given a linked list and a value x, partition it such that all nodes less than x come before nodes greater than or equal to x. You should preserve the 阅读全文
posted @ 2016-03-24 08:59 YuriFLAG 阅读(181) 评论(0) 推荐(0)
摘要: 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? 思路1:创建一个ArrayList用于保存每个节点的value,遍 阅读全文
posted @ 2016-03-24 08:41 YuriFLAG 阅读(174) 评论(0) 推荐(0)
摘要: Given a string containing just the characters '(', ')', '{', '}', '[' and ']', determine if the input string is valid. The brackets must close in the 阅读全文
posted @ 2016-03-23 11:33 YuriFLAG 阅读(175) 评论(0) 推荐(0)
摘要: 原理辗转相除法。 阅读全文
posted @ 2016-03-22 11:33 YuriFLAG 阅读(120) 评论(0) 推荐(0)
摘要: Given n pieces of wood with length L[i] (integer array). Cut them into small pieces to guarantee you could have equal or more than k pieces with the s 阅读全文
posted @ 2016-03-21 20:12 YuriFLAG 阅读(198) 评论(0) 推荐(0)