上一页 1 ··· 51 52 53 54 55 56 57 58 59 ··· 114 下一页
摘要: 这道题使用dfs会超时,看评论区也有人遇到同样的问题,比赛时调试了1个多小时尝试改进,没有意识到应该换用非递归的bfs可以解决,消耗了大量的时间。 超时的方案如下,使用python实现:(经过尝试,能通过的测试用例中,使用5个方向就可以了) 下面是AC的解决方案,使用bfs思想,代码如下: 阅读全文
posted @ 2019-06-16 12:24 Sempron2800+ 阅读(201) 评论(0) 推荐(0) 编辑
摘要: 1 class Solution: 2 def duplicateZeros(self, arr: List[int]) -> None: 3 """ 4 Do not return anything, modify arr in-place instead. 5 """ 6 n = len(arr 阅读全文
posted @ 2019-06-16 12:13 Sempron2800+ 阅读(195) 评论(0) 推荐(0) 编辑
摘要: 思路分析:将字符串的"{}"内的部分和常规字符分开处理。对于大括号内的部分,先将括号内的字符进行“组合”,然后再把常规字符插入到相应的位置。 本题的主要思想和leetcode17: Letter Combinations of a Phone Number是一样的。 阅读全文
posted @ 2019-06-15 23:56 Sempron2800+ 阅读(292) 评论(0) 推荐(0) 编辑
摘要: 1 class Solution: 2 def highFive(self, items: List[List[int]]) -> List[List[int]]: 3 n = len(items) 4 dic = {} 5 for item in items: 6 ids = item[0] 7 ... 阅读全文
posted @ 2019-06-15 23:55 Sempron2800+ 阅读(153) 评论(0) 推荐(0) 编辑
摘要: 1 class Solution: 2 def sumOfDigits(self, A: List[int]) -> int: 3 n = len(A) 4 if n == 0: 5 return 1 6 minnum = min(A) 7 strnum = str(minnum) 8... 阅读全文
posted @ 2019-06-15 23:54 Sempron2800+ 阅读(144) 评论(0) 推荐(0) 编辑
摘要: 把字符串转换成整数 将一个字符串转换成一个整数(实现Integer.valueOf(string)的功能,但是string不符合数字要求时返回0),要求不能使用字符串转换整数的库函数。 数值为0或者字符串不是一个合法的数值则返回0。 阅读全文
posted @ 2019-06-14 20:23 Sempron2800+ 阅读(114) 评论(0) 推荐(0) 编辑
摘要: 构建乘积数组 给定一个数组A[0,1,...,n-1],请构建一个数组B[0,1,...,n-1],其中B中的元素B[i]=A[0]*A[1]*...*A[i-1]*A[i+1]*...*A[n-1]。不能使用除法。 思路:先构建mat二维数组,这个矩阵的特点是,主对角线都是1。从每一行来看,除了在 阅读全文
posted @ 2019-06-14 20:16 Sempron2800+ 阅读(162) 评论(0) 推荐(0) 编辑
摘要: 不用加减乘除做加法 写一个函数,求两个整数之和,要求在函数体内不得使用+、-、*、/四则运算符号。机智的方案啊。 1 # -*- coding:utf-8 -*- 2 class Solution: 3 def Add(self, num1, num2): 4 return sum([num1,nu 阅读全文
posted @ 2019-06-14 19:49 Sempron2800+ 阅读(180) 评论(0) 推荐(0) 编辑
摘要: 求1+2+...+n 求1+2+3+...+n,要求不能使用乘除法、for、while、if、else、switch、case等关键字及条件判断语句(A?B:C)。 1 # -*- coding:utf-8 -*- 2 class Solution: 3 def Sum_Solution(self, 阅读全文
posted @ 2019-06-14 19:42 Sempron2800+ 阅读(125) 评论(0) 推荐(0) 编辑
摘要: 圆圈中最后剩下的数字 每年六一儿童节,牛客都会准备一些小礼物去看望孤儿院的小朋友,今年亦是如此。HF作为牛客的资深元老,自然也准备了一些小游戏。其中,有个游戏是这样的:首先,让小朋友们围成一个大圈。然后,他随机指定一个数m,让编号为0的小朋友开始报数。每次喊到m-1的那个小朋友要出列唱首歌,然后可以 阅读全文
posted @ 2019-06-14 19:31 Sempron2800+ 阅读(134) 评论(0) 推荐(0) 编辑
上一页 1 ··· 51 52 53 54 55 56 57 58 59 ··· 114 下一页