码迷,mamicode.com
首页 > 编程语言 > 详细

和为s的正数序列-python

时间:2019-08-10 17:49:53      阅读:96      评论:0      收藏:0      [点我收藏+]

标签:==   tail   article   除法   sdn   tps   enc   python2   detail   

思路:参考https://blog.csdn.net/qq_41822235/article/details/82109081 里面的方法4
同时因为python2.7的原因,除法会省去小数点后面的数字,if语句那里加了一句ij == 2tsum,

# -*- coding:utf-8 -*-
class Solution:
    def FindContinuousSequence(self, tsum):
        # write code here
        res = []
        for i in range((tsum)//2+1, 1, -1):
            j = 2*tsum / i
            if i*j == 2*tsum and (j-i+1)>0 and (j-i+1) % 2 == 0:
                res.append([ii+(j-i+1)/2 for ii in range(i)])
        return res

和为s的正数序列-python

标签:==   tail   article   除法   sdn   tps   enc   python2   detail   

原文地址:https://www.cnblogs.com/dolisun/p/11332087.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!