func clumsy(N int) int {
var ary []int
for n := N; n >= ; n-- {
ary = append(ary, n)
}
re := N % //4个数字一组
firstgroup := true
//最后一组如果不够4个,就补充到4个值,*和/补充1,+和-补充0,这样结果不变
if re == {
//不用补充
} else if re == {
//补充3个
ary = append(ary, ) //补充*1
ary = append(ary, ) //补充/1
ary = append(ary, ) //补充+0
} else if re == {
ary = append(ary, ) //补充/1
ary = append(ary, ) //补充+0
} else if re == {
ary = append(ary, ) //补充+0
}
n := len(ary) //长度是4的倍数
var sum int
for a := ; a <= n-; a += {
temp := ary[a] * ary[a+] / ary[a+]
if firstgroup { //第一组的G1*G2/G3是正
firstgroup = false
} else {
temp = temp * - //非第一组的G1*G2/G3是负
}
temp += ary[a+]
sum += temp
}
return sum
}

这道题的思路就是把运算映射到数组的index上,形成一种规律的运算方式,在循环中进行处理。

leetcode1006的更多相关文章

  1. leetcode-1006 Construct Binary Tree from Inorder and Postorder Traversal

    Given inorder and postorder traversal of a tree, construct the binary tree. Note:You may assume that ...

  2. [Swift]LeetCode1006. 笨阶乘 | Clumsy Factorial

    Normally, the factorial of a positive integer n is the product of all positive integers less than or ...

随机推荐

  1. sql培训

    1.select--查询语句 select * from table; select cols from table; select cols from table where condition; ...

  2. go学习day3

    strings和strconv使用 1.strings.HasPrefix(s string, prefix string) bool:判断字符串s是否以prefix开头 2.strings.HasS ...

  3. Spring-boot+Spring-batch+hibernate+Quartz简单批量读文件写数据用例

    本文程序集成了Spring-boot.Spring-batch.Spring-data-jpa.hibernate.Quartz.H2等.完整代码在Github上共享,地址https://github ...

  4. Web jsp开发学习——前端后台传参方法

    一.前端传后台: 1.1表单数据的传递   前端的表单里定义名字name   后台通过名字获取输入的值         1.2页面点击了哪个按钮传递 登录注销的另一种方式   点击登录的地方设置参数 ...

  5. 学习笔记之Nginx

    NGINX | High Performance Load Balancer, Web Server, & Reverse Proxy https://www.nginx.com/ flawl ...

  6. linux 查看进程启动路径

    在linux下查看进程大家都会想到用 ps -ef|grep XXX 可是看到的不是全路径,怎么看全路径呢? 每个进程启动之后在 /proc下面有一个于pid对应的路径 例如:ps -ef|grep ...

  7. 字符编码-ASCII,GB2312,GBK,GB18030

    ASCII ASCII,GB2312,GBK,GB18030依次增加,向下兼容. 手机只需要支持GB2312 电脑中文windows只支持GBK 发展历程 如果你使用编译器是python2.0版本,默 ...

  8. 在MySQL中实现Rank高级排名函数

    MySQL中没有Rank排名函数,当我们需要查询排名时,只能使用MySQL数据库中的基本查询语句来查询普通排名.尽管如此,可不要小瞧基础而简单的查询语句,我们可以利用其来达到Rank函数一样的高级排名 ...

  9. InfluxDB 基本认识

    一.InfluxDB 简介 InfluxDB 是用Go语言编写的一个开源分布式时序.事件和指标数据库,无需外部依赖.类似的数据库有Kairosdb.OpenTsdb等. 三大特性: 时序性(Time ...

  10. OpenCV安装教程(Ubuntu 18.04)

    视频教程 带字幕版: https://www.youtube.com/watch?v=0vjC2UHptU4 无带字幕版:https://fzhshared-1252154746.cos.ap-gua ...