LeetCode 6034. 数组的三角和
文章目录
- 1. 题目
- 2. 解题
1. 题目
给你一个下标从 0 开始的整数数组 nums ,其中 nums[i] 是 0 到 9 之间(两者都包含)的一个数字。
nums 的 三角和 是执行以下操作以后最后剩下元素的值:
- nums 初始包含 n 个元素。如果 n == 1 ,终止 操作。否则,创建 一个新的下标从 0 开始的长度为 n - 1 的整数数组 newNums 。
- 对于满足
0 <= i < n - 1
的下标 i ,newNums[i] 赋值 为(nums[i] + nums[i+1]) % 10
,% 表示取余运算。 - 将 newNums 替换 数组 nums 。
- 从步骤 1 开始 重复 整个过程。
请你返回 nums 的三角和。
示例 1:
输入:nums = [1,2,3,4,5]
输出:8
解释:
上图展示了得到数组三角和的过程。示例 2:
输入:nums = [5]
输出:5
解释:
由于 nums 中只有一个元素,数组的三角和为这个元素自己。提示:
1 <= nums.length <= 1000
0 <= nums[i] <= 9
来源:力扣(LeetCode)
链接:https://leetcode-cn.com/problems/find-triangular-sum-of-an-array
著作权归领扣网络所有。商业转载请联系官方授权,非商业转载请注明出处。
2. 解题
- 按题意模拟
class Solution {public:int triangularSum(vector<int>& nums) {int n = nums.size();for(int i = 0; i < n-1; ++i){for(int j = 0; j < n-1; ++j)nums[j] = (nums[j]+nums[j+1])%10;}return nums[0];}
};
376 ms 18.1 MB C++
我的CSDN博客地址 https://michael.blog.csdn.net/
长按或扫码关注我的公众号(Michael阿明),一起加油、一起学习进步!
LeetCode 6034. 数组的三角和相关推荐
- 3、leetcode 697 数组的度
leetcode 697 数组的度 给定一个非空且只包含非负数的整数数组 nums,数组的度的定义是指数组里任一元素出现频数的最大值. 你的任务是在 nums 中找到与 nums 拥有相同大小的度的最 ...
- angularjs 元素重复指定次数_[LeetCode] 442. 数组中重复的数据
[LeetCode] 442. 数组中重复的数据 题目链接: https://leetcode-cn.com/problems/find-all-duplicates-in-an-array 难度:中 ...
- 弟中弟的Leetcode总结——数组类(十一)
弟中弟的Leetcode总结--数组类(十一) 题目描述 Single Number Given a non-empty array of integers, every element appear ...
- 弟中弟的Leetcode总结——数组类(十)
弟中弟的Leetcode总结--数组类(十) 题目描述 Climbing Stairs You are climbing a stair case. It takes n steps to reach ...
- 弟中弟的Leetcode总结——数组类(五)
弟中弟的Leetcode总结--数组类(五) 题目描述 Remove Duplicates from Sorted Array Given a sorted array nums, remove th ...
- 弟中弟的Leetcode总结——数组类(二)
弟中弟的Leetcode总结--数组类(二) 题目描述 Container With Most Water Given n non-negative integers a1, a2, -, an , ...
- 弟中弟的Leetcode总结——数组类(四)
弟中弟的Leetcode总结--数组类(四) 题目描述 Two Sum Given an array of integers, return indices of the two numbers su ...
- 弟中弟的Leetcode总结——数组类(八)
弟中弟的Leetcode总结--数组类(八) 题目描述 Combination Sum Given a set of candidate numbers (candidates) (without d ...
- 弟中弟的Leetcode总结——数组类(九)
弟中弟的Leetcode总结--数组类(九) 题目描述 Subsets Given a set of distinct integers, nums, return all possible subs ...
最新文章
- jquery selector 基础
- 亚洲游戏行业遭遇史上最大DDoS攻击,微软:我给扛下来了
- bzoj1013球形空间
- 72年属鼠48岁有一灾2020_李半仙推算:1972年虚岁48岁属鼠人,2020年干什么最能发财??...
- Qt工作笔记-获取选中的文件名(lastIndexOf的使用)
- 奇安信代码卫士帮助微软和 Oracle 修复多个高危漏洞,获官方致谢
- JAVA 入门教程 2
- AI芯片发展的前世今生
- 【Linux】【开发环境】【RHEL】开发环境搭建系列之四——安装daytime服务
- matlab regress RMSE,在利用regress进行多元线性回归中出现的问题
- Docker----Consul集群搭建
- 电脑录像软件推荐?分享3款,简单好用且方便
- 成功解决图像相减全黑问题
- Mapper未生成impl
- liteos简介(一)
- RGB显示屏的辐射超标问题点及解决方案
- 计算机开机无法进入桌面,电脑开机不能进入系统界面的故障修复
- Python系列模拟登录之网易云个人听歌排行榜爬取 !
- css首字下沉_一个简单CSS首字下沉
- 1071 小赌怡情(15分)
热门文章
- 深度学习之递归神经网络(Recurrent Neural Network,RNN)
- SecureCRT常用的使用技巧
- pycharm之no python interpreter configured for project的解决办法
- java中为什么设计包装类,Java 中为什么要设计包装类
- 第一季2:视频设备开发的技术流
- 游戏大厅 从基础开始(7)--绕回来细说聊天室(中间偏下)之女仆编年史2
- 学习《深度学习入门:基于Python的理论与实现》高清中文版PDF+源代码
- 周记之琢磨下计算机网络(2018/10/22-2018/10/28)
- Ogg入门--基本命令
- 017-通过govendor管理依赖包