#-*- coding: UTF-8 -*-
#超时
#        lenA=len(A)
#        maxSum=[]
#        count=0
#        while count<lenA:
#            tmpSum=0
#            for i in xrange(lenA):
#                tmpSum+=i*A[i-count]
#            maxSum.append(tmpSum)
#            count+=1
#        return max(maxSum)

#AC源码如下
class Solution(object):
    def maxRotateFunction(self, A):
        """
        :type A: List[int]
        :rtype: int
        """
        if A==[]:return 0
        sumA=sum(A)
        lenA=len(A)
        preF=0
        for i in xrange(lenA):
            preF+=i*A[i]
        count=1;maxSum=preF
      
        while count<lenA:
            curF=preF+sumA-lenA*A[-count]
            count+=1;preF=curF
            if maxSum<=curF:maxSum=curF
     
        return maxSum

sol=Solution()
print sol.maxRotateFunction([4,3,2,6])

【leetcode❤python】 396. Rotate Function的更多相关文章

  1. 【leetcode❤python】 189. Rotate Array

    #-*- coding: UTF-8 -*-#由于题目要求不返回任何值,修改原始列表,#因此不能直接将新生成的结果赋值给nums,这样只是将变量指向新的列表,原列表并没有修改.#需要将新生成的结果赋予 ...

  2. 【leetcode❤python】Sum Of Two Number

    #-*- coding: UTF-8 -*- #既然不能使用加法和减法,那么就用位操作.下面以计算5+4的例子说明如何用位操作实现加法:#1. 用二进制表示两个加数,a=5=0101,b=4=0100 ...

  3. 【LeetCode】396. Rotate Function 解题报告(Python)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 题目地址:https://leetcode.com/problems/rotate-fu ...

  4. 【leetcode❤python】 1. Two Sum

    #-*- coding: UTF-8 -*- #AC源码[意外惊喜,还以为会超时]class Solution(object):    def twoSum(self, nums, target):  ...

  5. 【leetcode❤python】 58. Length of Last Word

    #-*- coding: UTF-8 -*-#利用strip函数去掉字符串去除空格(其实是去除两边[左边和右边]空格)#利用split分离字符串成列表class Solution(object):   ...

  6. 【leetcode❤python】 8. String to Integer (atoi)

    #-*- coding: UTF-8 -*-#需要考虑多种情况#以下几种是可以返回的数值#1.以0开头的字符串,如01201215#2.以正负号开头的字符串,如'+121215':'-1215489' ...

  7. 【leetcode❤python】 165. Compare Version Numbers

    #-*- coding: UTF-8 -*-class Solution(object):    def compareVersion(self, version1, version2):       ...

  8. 【leetcode❤python】 168. Excel Sheet Column Title

    class Solution(object):    def convertToTitle(self, n):        """        :type n: in ...

  9. 【leetcode❤python】 7. Reverse Integer

    #-*- coding: UTF-8 -*-#2147483648#在32位操作系统中,由于是二进制,#其能最大存储的数据是1111111111111111111111111111111.#正因为此, ...

随机推荐

  1. 生成一行html

    //压缩 一行html Regex regReplaceBlank = new Regex(">(\\s+)<", RegexOptions.IgnoreCase); ...

  2. springmvc Failed to load resource: the server responded with a status of 404 (Not Found)

    jsp页面导入css.js提示上述问题. Spring对静态资源的请求做专门处理 <!-- 对静态资源的请求 --><mvc:resources location="/js ...

  3. Interface => IDataErrorInfo

    Introduction to common Interfaces IDataErrorInfo Provides the functionality to offer custom error in ...

  4. NEC学习 ---- 布局 -三列,左侧自适应

    效果图: html代码: <div id="demo4"> <div class="g-bd4 f-cb"> <div class ...

  5. log4j.properties 配置的学习整理

    参考资料: log4j.properties:用来做什么的(日志) Log4j:由2部分组成 :loggers(记录器)            ----日志的类别 appender(输出源)     ...

  6. 程序最多能new多少内存(2G内存里要放程序的5大区,HeapAlloc比new要快多了,而且超过2G的时候会告诉你)

    根据<Windows核心编程>得知:X86操作系统提供每个程序最多只有4G的虚拟内存,其中2G虚拟内存提供给系统用(具体用来干什么还待考察),还有2G的内存留给用户使用.那这2G内存能拿来 ...

  7. oracle: tochar(sysdate,'D')函数

    学习oracle时碰到tochar(sysdate,'D')函数,但是发现并不是星期几,如今天是20150317,周二,但是得到的值为3 开始以为是系统日期什么的原因,试了试 select to_ch ...

  8. LeetCode Strobogrammatic Number II

    原题链接在这里:https://leetcode.com/problems/strobogrammatic-number-ii/ 题目: A strobogrammatic number is a n ...

  9. iOS:最详细的创建CocoaPods私有库教程

    一.感慨 说实话,创建这个CocoaPods私有库,我愣是搞了两个星期,创建的过程中,自己的感情波动是这样的:激情四射---->有点困惑----->极度困惑----->有点失望--- ...

  10. 微信sdk分享,苹果手机分享到qq好友和qq空间没有反应

    最近线上程序苹果手机进行微信分享时,分享到qq好友和qq空间,无法调用分享程序,从微信跳转到qq后就没有反应了,但是安卓手机分享就没事? 解决:调用微信sdk分享时,分享的url(link)的参数不能 ...