lyfeng01
lyfeng01
全部文章
分类
题解(18)
归档
标签
去牛客网
登录
/
注册
lyfeng01的博客
全部文章
(共15篇)
题解 | #统计每个月兔子的总数#
这个月的兔子数量=上个月的+新出生的 新出生的 = 上上个月的 def cal(n)=begin return 0 if n == 0 if n < 3 1 else cal(n-1) + cal(n-2) end=end return...
2021-08-10
0
275
题解 | #汽水瓶#
ns = []while (line = STDIN.gets) break if line.to_i == 0 ns << line.to_iend results = [] ns.each{|n| results << n/2.to_i}puts res...
2021-08-10
0
237
题解 | #汽水瓶#
def get_sum(n) sum = 0 sum = n/3.to_i @all_sum += sum # 换完之后的总瓶子数 &...
2021-08-10
0
283
题解 | #最长回文子串#
参考 理论支持:每当增加一个新的字母,最大回文串的长度只能增加1或者2,不可能增加更多,并且,新的最大回文串必然要包含这个字母! 证明:如果新增了一个字母,最大回文串的长度增加了3,这是不可能的,例如:abcdefgfedcba,当增加到最后的b或者a时,是不可能增加3个长度的,因为每增加一个字母,...
2021-08-07
0
323
题解 | #买卖股票的最好时机#
代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 @param prices int整型一维数组 @return int整型 class Solution def maxProfit(prices) # write code here r...
2021-08-07
0
306
题解 | #最长递增子序列#
class Solution def LIS(arr) # write code here result = [] # 每一次遍历重排后的排序队列 ...
2021-08-07
0
381
题解 | #斐波那契数#
return n if n <=1 a, b, c = 0, 1, 1 (2..n).each{|i| c = ...
2021-08-06
0
276
题解 | #螺旋矩阵#
return [] if matrix.length == 0 || matrix[0].length == 0 ls = [] #返回的数组 up, down = 0, matrix.length-1 left, right = 0, matrix[0].lengt...
2021-08-06
1
371
题解 | #坐标移动#
line = STDIN.gets.delete("\n")ms = line.split(";")x , y = 0, 0ms.each{|m| if m[/[A|S|W|D]-?\d+/] == m depth = m[/\d+/].to_i de...
2021-08-03
0
329
题解 | #质数因子#
line = STDIN.gets().to_ils = ""last_index = 2new_line = line.clone(0...Math.sqrt(line)).each do |t| one_flag = false (2..Math.sqrt(lin...
2021-08-01
0
290
首页
上一页
1
2
下一页
末页