摘要: 春节期间小明使用微信收到很多个红包,非常开心。在查看领取红包记录时发现,某个红包金额出现的次数超过了红包总数的一半。请帮小明找到该红包金额。写出具体算法思路和代码实现,要求算法尽可能高效。 给定一个红包的金额数组gifts及它的大小n,请返回所求红包的金额。 测试样例: 阅读全文
posted @ 2016-03-27 09:58 YuriFLAG 阅读(315) 评论(0) 推荐(0)
摘要: 在一组数的编码中,若任意两个相邻的代码只有一位二进制数不同, 则称这种编码为格雷码(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)