当前位置:网站首页>【JZ64 求1+2+3+...+n】
【JZ64 求1+2+3+...+n】
2022-07-30 10:37:00 【爱吃榴莲的喵星人】
一、题目描述
二、题目代码
提示:内部类实现
class Solution {
private:
class Sum
{
public:
Sum()
{
_ret += _i;
_i++;
}
};
static int _ret;
static int _i;
public:
int Sum_Solution(int n) {
Sum arr[n];
return _ret;
}
};
int Solution::_ret = 0;
int Solution::_i = 1;
class Sum
{
public:
Sum()
{
_ret += _i;
_i++;
}
static int get_ret()
{
return _ret;
}
private:
static int _ret;
static int _i;
};
int Sum::_ret = 0;
int Sum::_i = 1;
class Solution {
public:
int Sum_Solution(int n) {
Sum arr[n];
return Sum::get_ret();
}
};
以上是本篇文章的全部内容,如果文章有错误或者有看不懂的地方,多和喵博主交流。互相学习互相进步。如果这篇文章对你有帮助,可以给喵博主一个关注,你们的支持是我最大的动力。
边栏推荐
猜你喜欢
随机推荐
PanGu-Coder: 函数级的代码生成模型
@RequestBody 和 @ResponseBody 详解
Meikle Studio - see the actual combat notes of Hongmeng device development 4 - kernel development
Adaptive Control - Simulation Experiment 1 Designing Adaptive Laws Using Lyapunov's Stability Theory
Array of Shell System Learning
MySQL之数据库维护
Shell system learning function
鸿湖万联扬帆富设备开发板正式合入OpenHarmony主干
图像去噪——Neighbor2Neighbor: Self-Supervised Denoising from Single Noisy Images
async.js入门
PyQt5 - draw sine curve with pixels
Flink_CDC construction and simple use
第1章 Kali与靶机系统
By building a sequence table - teach you to calculate time complexity and space complexity (including recursion)
梅科尔工作室-看鸿蒙设备开发实战笔记七——网络应用开发
4. yolov5-6.0 ERROR: AttributeError: 'Upsample' object has no attribute 'recompute_scale_factor' solution
死锁的理解
Log4j有哪几种日志级别呢?
Practical Walkthrough | Calculate Daily Average Date or Time Interval in MySQL
现在报PMP还来得及参加9月的考试吗?分享敏捷全真模拟题










