LeetCode Count and Say

[Bug已解决] CUDA error 尽管 CUDA 可用且 GPU 受支持-通用排查 RuntimeError 解决方案 阅读详情

原题链接在这里:https://leetcode.com/problems/count-and-say/

当前的读音用来做数列的下一个"1" 读成1个1,写成"11"用来作为下一个。

从i = 2开始一直到n作为外层loop, i是第 ith 个结果。

进入循环后,新生成count = 1, index = 1, 然后进入内层loop, 用index 从第二位走res, 现字符等同于前字符就count++, 不同字符就先append count, 然后 append 前字符,然后count归为1. 走完内层loop, 再把最后一段的count, 字符加到StringBuilder中。

Note:  count, StringBuikder,index 都需要在外层循环归回原数。

AC Java:

public class Solution {
    public String countAndSay(int n) {
        if(n<=0){
            return "";
        }
        if(n==1){
            return "1";
        }
        String res = "1";
        for(int i = 2; i<=n; i++){
            int count = 1;
            StringBuilder sb = new StringBuilder();
            int index = 1;
            for( index = 1; index<res.length(); index++){
                if(res.charAt(index) == res.charAt(index-1)){
                    count++;
                }else{
                    sb.append(count);
                    sb.append(res.charAt(index-1));
                    count = 1;
                }
            }
            sb.append(count);
            sb.append(res.charAt(index-1));
            res = sb.toString();
        }
        return res;
    }
}


15、z/OS 优化配置与迁移实践 本文详细探讨了z/OS环境的优化配置与迁移实践,涵盖DASD存储库管理、用户目录更新、环境更新意义以及不同场景下的迁移案例。通过单笔记本系统和服务器级机器的实例,展示了迁移流程和关键要点,包括DASD文件创建、设备映射更新、系统重启初始化以及数据备份等步骤。文章还总结了迁移过程中的注意事项,并展望了未来z/OS优化的发展趋势,为z/OS系统的稳定运行和高效管理提供了实用指导。 阅读详情

相关推荐

别再用Excel画波特图了!用LTspice免费仿真软件,5分钟搞定电路传递函数分析

本文介绍了如何利用LTspice免费仿真软件高效绘制波特图,解决传统Excel绘图效率低、精度不足的问题。通过详细的操作步骤和实战案例,展示LTspice在电路传递函数分析中的自动化计算、专业级精度和完整特性展示等优势,帮助工程师快速完成频率响应分析。

weixin_42524226的博客 460

LeetCode38——Count and Say

LeetCode38——Count and Say 上一题对我来说实在太凶残了,所以我还是缓缓先做38题好了。。。 题意: 可以理解为求一个数组的第n项,而这个数组的通项公式可以这样理解: 第1项:1 第2项:11 第3项:21 第4项:1211 第5项:111221 第6项:312211 ... ... 第n项:第n-1项的数字串从左到右读出来。

上善若水 4489

Centos7 XFS(dm-0):Internal error XFS_WANT_CORRUPTED_GOTO

在k8s的道路上我们都是小白,每天启动虚机都会遇到各种各样的问题,这不。部署的k8s虚机启动发现操作系统启动异常,提示如下报错信息。进入/dev/mapper目录下,查询目录下路径信息。可以通过对文件系统进行修复操作,操作如下。重启完成后虚机恢复正常登录。

hedao0515的专栏 4583

Leetcode1-100: 38. Count and Say

Leetcode1-100: 38. Count and Say问题描述解题思路代码实现 问题描述 题目要求: 输入一个数字,输出这个数字代表的count-and-say字符串,注意每个数字对应的字符串需要根据上一个数字的字符串来得出(例如4对应的是1211,就是1个1,1个2,2个1,所以5对应的字符串就是111221) 解题思路 比较简单,直接brute force,迭代从1往后解,每次把上一个的结果最后下一个的输入来做即可。 代码实现 public String countAndSay(int n)

Y123iwantit的博客 301

手把手教你用Arduino Uno控制meArm机械臂(附完整代码+避坑指南)

本文提供了一份详尽的meArm机械臂控制指南,涵盖从Arduino Uno硬件连接到Servo库编程的完整流程。重点讲解了如何通过独立供电、软件限位和平滑运动函数实现稳定控制,并设计了串口指令协议与高级功能,帮助创客有效规避舵机抖动、电源不足等常见问题,让机械臂运行更流畅可靠。

gpt4scribbler的博客 540

IC芯片验证 - 手把手教你搭建UVM验证环境

这是一个UVM的demo项目

howard789的博客 3万+

[Leetcode] Count and Say

class Solution { public: string countAndSay(int n) { // Start typing your C/C++ solution below // DO NOT write int main() function string s = "1"; for (int

AlgorithmEngine 777

RC4加密算法详解

RC4(也称为 Rivest Cipher 4)是流密码的一种形式,流密码逐字节操作数据流。RC4 流密码是使用最广泛的流密码之一,它通过算法一次一个字节地加密消息,简单并且操作速度快。RC4是一种在电子信息领域加密的技术手段,用于无线通信网络,是一种电子密码,只有经过授权的用户才能享受该服务,使用 64 位或 128 位密钥大小。它通常用于安全套接层 (SSL)、传输层安全 (TLS) 等应用,也用于 IEEE 802.11 无线 LAN 标准。在存储大量的信息时,RC4展现出它的实用性,面对大量的数据,

weixin_43211186的博客 1万+

LeetCode 38 -- Count and Say

LeetCode 38 -- Count and Say The count-and-say sequence is the sequence of integers beginning as follows: 1, 11, 21, 1211, 111221, ... 1 is read off as "one 1" or 11. 11 is read off as

yiayia070614的博客 299

c++中,部署Ethercat IGH + PREEMPT_RT 环境,跑DC模式,如何实现?

🏆本文收录于 《全栈 Bug 调优(实战版)》 专栏。专栏聚焦真实项目中的各类疑难 Bug,从成因剖析 → 排查路径 → 解决方案 → 预防优化全链路拆解,形成一套可复用、可沉淀的实战知识体系。无论你是初入职场的开发者,还是负责复杂项目的资深工程师,都可以在这里构建一套属于自己的「问题诊断与性能调优」方法论,助你稳步进阶、放大技术价值 。

**My Coding Family** 1355

手把手教你学Simulink--基于电能质量与无功补偿的场景实例:统一电能质量调节器(UPQC)的联合控制仿真

在现代电力系统中,电能质量问题有源电力滤波器(APF)→ 治理谐波与无功动态电压恢复器(DVR)→ 补偿电压暂降/暂升静止无功发生器(SVG)→ 无功补偿与电压支撑而统一电能质量调节器(Unified Power Quality Conditioner, UPQC)是一种集串联补偿与并联补偿于一体的全能型电能质量治理装置✅ 电压类问题:暂降、暂升、不平衡、闪变✅ 电流类问题:谐波、无功、三相不平衡✅ 实现双向有功交换(储能型)串联单元(DVR功能):串联于线路,控制电源侧电压质量并联单元。

MHD0815的博客 236

LeetCode - 38. Count and Say(36ms)

LeetCode - 38. Count and Say(36ms) The count-and-say sequence is the sequence of integers with the first five terms as following: 1....

dichunpu6524的博客 140

A100 NVLink集群极致优化指南

《A100 NVLink集群通信优化指南》摘要:针对A100 80G SXM机型NVLink 3.0集群,提供硬件配置检查方法(nvidia-smi topo -m)和强制启用指令。重点介绍NCCL参数调优(算法选择、低延迟协议配置)、GPUDirect RDMA启用步骤,以及单机/多机场景下的通信模式选择。包含PyTorch all_reduce基准测试方法,并给出带宽异常排查方案(dmesg检查、NCCL缓存重置)。通过CUDA Graph通信重叠和混合精度优化,可实现90%+带宽利用率。附猿界算力监控

2401_89353317的博客 583

[LeetCode]38. Count and Say

[LeetCode]38. Count and Say题目描述思路字符串拼接,暴力遍历即可代码#include <iostream> #include <string>using namespace std;class Solution { public: string countAndSay(int n) { if (n == 0) return "

Lcharon的博客 481

VC中sqlite的使用

在VC中对sqlite的使用,实现数据库大批数据的快速插入,读取数据库中的数据在ListCtrl中显示

计算机控制技术及应用

《计算机控制技术及应用》通过总结作者的科研成果和吸收国内外的先进理论、方法和技术,以计算机控制系统的网络化、开放化、智能化和集成化发展趋势为主线索,主要介绍计算机控制系统的基本概念和计算机控制系统的典型形式,计算机控制系统的数学描述与基本分析方法,以及数字PID控制器、最少拍控制系统、达林算法、状态变量设计法等设计方法及其各种改进算法。重点突出计算机控制系统输入输出通道接口的设计方法和典型控制系统的设计案例与实现方法等。

LeetCode Notes_#38 Count and Say

LeetCode Notes_#38 Count and SayLeetCode Contents 题目思路和解答题意思路解答总结 题目 The count-and-say sequence is the sequence of integers with the first five terms as following: 1.1 2.11 3.21 4.1211 5...

baji9701的博客 181

霍尼韦尔SoftMaster使用说明

霍尼韦尔SoftMaster使用说明

leetcode 38. Count and Say

leetcode 38. Count and Say 题目大意:读出每个字符串。譬如说 1 读作 11 11 读作 21 21 读作 1211

编码之路 368

数学建模模型总结

这是本人在两年内准备参加数学建模竞赛搜集到的模型资料,已经经过了本人的筛选和整理,希望能够对准备参加数学建模竞赛的学弟学妹们提供一些帮助!

[Leetcode]38--Count and Say

[leetcode] 38. Count and Say题目链接:https://leetcode.com/problems/count-and-say/The count-and-say sequence is the sequence of integers beginning as follows: 1, 11, 21, 1211, 111221, …1 is read off as “on

weixin_37553155的博客 209

leetcode-38 Count and Say

开始没看懂题目,查了一下……囧。 思路很清晰,自己写的程序经过修改精简后,如下:class Solution { public: string countAndSay( int n){ if( n <= 0)//排除不符合条件的n return "";//输出为空 string say = "1";//用于保存结果,初始化为“1” for( int i = 1; i

evolone的专栏 434

LeetCode力扣之Count and Say

The count-and-say sequence is the sequence of integers with the first five terms as following:1. 1 2. 11 3. 21 4. 1211 5. 111221 1 is read off as "one 1" or 11.11 is read off as "t...

LeeWei 240

《leetCode》:Count and Say

题目The count-and-say sequence is the sequence of integers beginning as follows: 1, 11, 21, 1211, 111221, ...1 is read off as "one 1" or 11. 11 is read off as "two 1s" or 21. 21 is read off as "one 2, th

wojiushimogui的博客 591

[leetcode]count and say2

class Solution { public: //when see str, return count and say of str string process(const string& str){ if (str == "") return ""; int l = 0; ...

weixin_30642561的博客 64

leetcode-38. Count and Say

leetcode-38. Count and Say题目: The count-and-say sequence is the sequence of integers beginning as follows: 1, 11, 21, 1211, 111221, … 1 is read off as “one 1” or 11. 11 is read off as “two

千念飞羽的专栏 331

LeetCode集锦(十二) - 第38题 Count and Say

LeetCode集锦(十二) - 第38题 Count and Say 问题 The count-and-say sequence is the sequence of integers with the first five terms as following: 1. 1 2. 11 3. 21 4. 1211 5. 111221 1 is ...

weixin_34361881的博客 142

leetcode38. Count and Say

leetcode38. Count and Say

慕鹞 187

leetcode 38.外观数列(count and say)C语言

leetcode 38.外观数列(count and say)C语言1.description2.solution 1.description https://leetcode-cn.com/problems/count-and-say/ 「外观数列」是一个整数序列,从数字 1 开始,序列中的每一项都是对前一项的描述。前五项如下: 1 11 21 1211 111221 1 被读作 “one 1” (“一个一”) , 即 11。 11 被读作 “two 1s” (“两个

hsk6543210的博客 688

LeetCode 38. Count and Say

LeetCode 38. Count and Say 报数序列是指一个整数照其中的整数的顺序按行报数,得到下一个数。其前五项如下: 1 11 21 1211 111221 1 被读作 “one 1” (“一个一”) , 即 11。 11 被读作 “two 1s” (“两个一”), 即 21。 21 被读作 “one 2”, “one 1” (“一个二” , ...

qq_30122883的博客 220
上一篇: LeetCode Longest Common Prefix
下一篇: LeetCode Length of Last Word
Dylan_Java_NYC
博客等级 码龄11年 1粉丝 134原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值