#-*- 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. MyEclipse tomcat7.x 自定义项目部署路径

  2. 对C++下struct 和 类默认继承的认识

    #include <iostream> using namespace std; struct struct1{ int data1 ; double data2 ; struct1(){ ...

  3. C# 计时器

    一.Stopwatch 主要用于测试代码段使用了多少时间 使用方法: Stopwatch sw=new Stopwatch(); sw.Start(); ... sw.Stop(); Console. ...

  4. HDU 4358 Boring counting(莫队+DFS序+离散化)

    Boring counting Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 98304/98304 K (Java/Others) ...

  5. xx.substring(x,x)和xx.index()

    [转的]用一个例子解释: ip = "126.168.1.1"; i = ip.indexOf('.');                           这里默认从0开始找到 ...

  6. maven说

    maven打包命令:mvn assembly:assembly 打包成jar包需要修改配置把unpack改成false文件在: C:\Users\Administrator\.m2\repositor ...

  7. 制作大漠字库并用python调用大漠工具方法来识别文字

    1.制作字库 1.截取需要的图片 2.这里截取了"火狐主页"四个字,接下来抓取文字的颜色 3.颜色由是由三个部分组成,即R G B其中的R是由00-FF(16进制) 即0-255个 ...

  8. JMeter学习-010-JMeter 配置元件实例之 - CSV Data Set Config 参数化配置

    众所周知,在进行接口测试的过程中,需要创建不同的场景(不同条件的输入,来验证不同的入参的返回结果).因而,在日常的自动化接口监控或商品监控等线上监控过程中,需要配置大量的入参来监控接口的返回是否正确. ...

  9. LeetCode Two Sum II - Input array is sorted

    原题链接在这里:https://leetcode.com/problems/two-sum-ii-input-array-is-sorted/ 题目: Given an array of intege ...

  10. DNS子域授权与转发配置

    正向区域SUB_ZONE_NAME IN NS NSSERVER_SUB_ZONE_NAME NSSERVER_SUB_ZONE_NAME IN A IP .com xingxing.com. xin ...