#-*- 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. svn文件批量清除

    svn文件批量清除 http://files.cnblogs.com/files/douxuyao/clearsvn.rar

  2. mysql5.5手册读书日记(2)

    <?php /* * * MySQL_5.5中文参考手册 485开始 * * mysql> SELECT CASE 1 WHEN 1 THEN 'one' -> WHEN 2 THE ...

  3. CGContextAddCurveToPoint 的深入理解

    CGContextAddCurveToPoint 这个函数看上去一般般,仔细琢磨发现不简单,为什么三个点就可以确定一条曲线呢? 网上查了查,小小研究了一下下. 1.关键知识 窃取自 (http://l ...

  4. 欢快的使用Unity JSON吧

    0x01:前言 Unity 5.3加入了UnityUtility类,意味着Unity终于有了自己原生态的JSON库.Unity主要用来游戏开发,JSON做为游戏开发中最受欢迎的配置文件.在官方没有库支 ...

  5. LeetCode Reconstruct Itinerary

    原题链接在这里:https://leetcode.com/problems/reconstruct-itinerary/ 题目: Given a list of airline tickets rep ...

  6. ORA-12631 / TNS-12631: Username retrieval failed

    From Metalink: Problem Description:====================When your server is not connected to the netw ...

  7. iTween研究院之学习笔记Move移动篇

             最近项目中需要加入一些模型移动的小动画,学习过程中发现了iTween这个类库.它主要的功能就是处理模型从起始点到结束点之间运动的轨迹.(移动,旋转,音频,路径,摄像机等)它是一个开源 ...

  8. JSON风格指南-真经

    简介 JSON(JavaScript Object Notation) 是一种轻量级的数据交换格式.它基于ECMAScript的一个子集. JSON采用完全独立于语言的文本格式,但是也使用了类似于C语 ...

  9. Mybatis Oracle 更新时报错17090

     更新数据库时报错   查看数据库里的数据是已经更新了 . 我开始用的是注解@Update("......")调试了好久都找不到原因,因为单独执行更新语句是正确的,在项目里运行,数 ...

  10. CentOS-6 yum安装nginx php53 mysql55 搭建LNMP环境

    1.导入外部软件库 01.rpm -Uvh http://dl.iuscommunity.org/pub/ius/stable/Redhat/6/x86_64/epel-release-6-5.noa ...