LeetCode解题报告-- Count and Say

196、NPU的编译器开发:教程与示例代码编写 NPU编译器开发实战指南 摘要:本文分享了NPU编译器开发中的核心挑战与实战经验,通过具体代码示例展示了关键实现技术: 指令生成:必须考虑硬件特性(如地址对齐)和芯片配置抽象化 图优化:重点处理常见冗余结构(Reshape合并、BN融合),并注意数值稳定性 算子拆分:采用分块计算策略适配有限SRAM,需特别注意边界条件处理 内存分配:基于张量使用频率的贪心算法优化SRAM使用效率 文中包含多个真实踩坑案例: DMA地址未对齐导致硬件错误 BN融合时的除零风险 tile边界处理不当引起的精度下降 这些经验为开 阅读详情

题目:

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, then one 1” or 1211.
Given an integer n, generate the nth sequence.
Note: The sequence of integers will be represented as a string.
点击解题:Count and Say

分析:题意是要求通过程序生成一组符合题意要求的字符串,
题目难度不高,基本思路是:以n为例,直接从左向右扫描n-1字符串,计算出现相同数字的个数 ,直至扫描结束!示意图如下:初始:count = 1,,每遇到数字相同,count++,然后将count转为字符串或字符类型 + 当前数组字符 以此为规律找出nth字符串。
这里写图片描述

java代码: Accepted

public class Solution {
    public String countAndSay(int n) {
       String newS = "1";
       int count = 1;
       int i = 1;
       while(i < n){
           String s = newS;
           newS = "";
           for(int j = 0;j < s.length();j ++){
                if( (j + 1) < s.length() && s.charAt(j) == s.charAt(j + 1)){
                    count ++;
                }else{
                    newS = newS + count + s.charAt(j);
                    count = 1;
                }
            }
            i ++;
       }
       return newS;
    }
}

python代码 Accepted

class Solution(object):
    def countAndSay(self, n):
        """
        :type n: int
        :rtype: str
        """
        i = 1
        count = 1
        newS = "1"

        while i < n:
            s= newS
            newS = ""

            for j in range(len(s)):
                if((j + 1) < len(s) and s[j] == s[j + 1]):
                    count = count + 1
                else:
                    newS = newS + str(count) + s[j]
                    count = 1
            i = i + 1
        return newS
【2026最新】3分钟Windows极速部署OpenClaw,完整可复制命令+全链路避坑指南 很多新手在Windows环境部署OpenClaw时,总会遇到各种玄学问题:WSL环境配置失败、Docker镜像拉取超时、容器启动后无法访问、权限报错、数据丢失……网上大量教程要么是Linux环境的,要么是早已过时的旧版本配置,照着操作不仅没法3分钟部署,反而要花几小时踩坑填坑。 阅读详情

相关推荐

传感器:MQ-5燃气模块测量燃气值(底部附代码)

本篇文章介绍使用MQ-5燃气模块测量燃气值,CPU还是选择单片机,MQ-5主要使用的技术为ADC,燃气对于单片机来说是模拟信号,需要转换为数字信号,再经过相关计算公式将燃气模拟值转换成对应的燃气数值,便于人们方便查看。例如家庭使用燃气模块测量燃气值,如果燃气值超过一定的范围,可以外设一个报警装置,保证家庭的生命安全。(1)ADC(analog to digital converter)即模数转换器,它可以将模拟信号转换为数字信号。按照其转换原理主要分为逐次逼近型、双积分型、电压频率转换型三种。STM32F1

Mr_zhang1911116的博客 1万+

【LEET-CODE】38. Count and Say

Question: 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

D_Trump的博客 333

嵌入式调光控制库:轻量级软启/渐变/记忆逻辑实现

调光控制是智能照明系统的核心基础功能,涉及亮度调节、人机交互与电气安全多重需求。其底层原理依赖于对相位角或PWM占空比的精确时序控制,并需融合软启动、渐变过渡、状态记忆等工程化逻辑。这类轻量级调光行为逻辑层,不直接操作硬件寄存器,而是以确定性、无动态内存、可配置的方式封装用户意图到目标亮度值(0–100%)的映射过程,显著提升产品鲁棒性与跨平台复用能力。广泛应用于TRIAC交流调光、LED直流PWM驱动及DALI/Matter等智能照明协议网关中,尤其适合资源受限的Cortex-M系列MCU和FreeRTO

weixin_28949937的博客 579

count-and-say 计数和发言

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

John Will的博客 6027

互联网金融项目实战(大数据Hadoop hive)

什么是互联网金融? 互联网金融 --> 信贷(信用贷款) --> 支付宝率先搞了一个信用体系 互联网金融: 在线支付、P2P 银行: 只会锦上添画、不喜欢雪中送炭 银行害怕出现坏账 ( 储户存钱,银行放贷 赚个利息差 ) 银行是可以倒闭的 保险公司不允许倒闭 银行分为:商业银行(自生自灭的)和非商业银行(国家的) 中国工商银行 全球第一大行 招商银行(清朝的一个李鸿章) 中国银行(历史超过 100 年了) 国家政策:希望银行能够扶持中小型企业 p2p:网络借贷平台 民间吸纳贷款 -->

weixin_58276266的博客 1553

用Python+OpenCV搞定线激光相机标定:从棋盘格到3D点云的保姆级实战

本文详细介绍了使用Python和OpenCV进行线激光相机标定的全流程实战,从硬件准备到3D点云重建。涵盖相机内参标定、激光平面方程拟合、三维重建等关键技术,提供完整的代码实现和工程优化建议,帮助开发者实现毫米级精度的工业检测和三维测量系统。

weixin_29227425的博客 283

LeetCode Count and Say 解题报告

LeetCode Count and Say 解题报告 如何数(shu 三声) 数(shu 四声):1,11,21,1211,111221,312211,13112221,1113213211

算法的天空 1万+

全网最全的AItium Designer 16下载资源与安装步骤

Altium Designer 除了全面继承包括Protel 99SE、Protel DXP在内的先前一系列版本的功能和优点外,还增加了许多改进和很多高端功能。该平台拓宽了板级设计的传统界面,全面集成了FPGA设计功能和SOPC设计实现功能,从而允许工程设计人员能将系统设计中的FPGA与PCB设计及嵌入式设计集成在一起。...

WQ的博客 1万+

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 o

LovePeppa的专栏 521

人工智能的未来:从弱 AI 到通用人工智能(AGI)

从最初的简单自动化程序,到如今的深度学习大模型(如 ChatGPT、DeepSeek、Grok),AI 逐步从弱人工智能(Weak AI)向更智能、更自主的方向发展。AI 的发展将影响就业市场,取代重复性、低技能的工作,同时创造新的高技能岗位。尽管深度学习带来了巨大的进步,但它仍然依赖大量标注数据进行训练,对新环境的泛化能力有限,这也是当前 AI 迈向 AGI 的关键障碍之一。本文将探讨 AI 从弱 AI 进化到 AGI 的可能性,分析目前 AI 技术的局限性,并展望未来 AI 在各个行业的影响。

qq_20245171的博客 1万+

自动驾驶中的多传感器融合实战:用卡尔曼滤波搞定毫米波雷达与摄像头航迹对齐

本文深入探讨了自动驾驶中多传感器融合的实战技术,重点介绍了如何使用卡尔曼滤波实现毫米波雷达与摄像头的航迹对齐。通过分析传感器特性差异、时空同步挑战及工程化实现步骤,提供了包括状态向量定义、观测矩阵设计和故障检测机制在内的完整解决方案,最终实现0.15米以内的高精度航迹对齐。

weixin_28728495的博客 410

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 read off as "one 1" or 11. 11 is read o

nudt_oys的博客 3096

【WSL2 Win10】解决子系统中nividia-smi出现的Failed to initialize NVML GPU access blocked by the operating systeM

环境:WIN10专业版 WSL2 Ubuntu x64架构 尝试在WSL2中装CUDA,装好以后在wsl系统中输入nvidia-smi命令,结果报错。但是在Win10的CMD中正常显示 Failed to initialize NVML: GPU access blocked by the operating system Failed to properly shut down NVML: GPU access blocked by the operating system在网上搜了一下,没太多类似的情况

6745

LeetCode: Count and Say 解题报告

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...

weixin_33860722的博客 139

NTscan扫描工具

ntscan是一个扫描器,可以扫描没有密码和弱密码的共享,先到配置文件中填写猜测的用户名和密码,扫描过程中右侧出现的是扫描日志。

ssm框架搭建

这个是一个在idea上成功跑起来的ssm框架项目,保存在这里方便以后使用直接下载

【LeetCode】38. Count and Say 解题报告(Python)

题目解释: 这个题题目难以理解,参考了别人的题目解释才终于理解,原题的意思就是用一个新的字符串描述上一个字符串,用数字表示上一个: 当n=1时:输出1; 当n=2时,解释1,1读作1个 ,表示为11; 当n=3时,解释上一个11,读作2个1,表示为21;(注意相同数字的描述) 当n=4时,解释上一个21,读作1个2,一个1,表示为1211; 当n=5时,解释上一个1211,读作1个1,1个2,2个...

L141210113的专栏 476

假人有限元模型

假人模型,车辆碰撞假人有限元模型,适合做乘员安全的研究者利用

[LeetCode 解题报告]038. 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 1is read off as"one 1"or11.11is read off ...

CVer 106

[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 "one 1" or 11.

小榕流光的专栏 572

Leetcode #38. Count and Say 数数报数 解题报告

1 解题思想这道题就是按照每一位读一下数字,然手输出 比如123就是1个1,1个2,一个3,输出111213嗯,也就是先输出个数,然后输出元素做法就是扫描,统计了,统计连续相同的数字,毕竟Easy难度~~2 原题The count-and-say sequence is the sequence of integers beginning as follows: 1, 11, 21, 1211,

MebiuW的专栏 1771

[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 1s" or 21. 21 is rea

魔豆(Magicbean)的博客 431

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的博客 143

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

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

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

ych4513979的专栏 258

[leetcode] 38. Count and Say

Description 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 外观数列的Python和C++代码。

Learning from the mistakes 2929

Count and say[easy on LeetCode]

Count and say[easy on LeetCode]原题地址:https://leetcode.com/problems/count-and-say/description/题目描述The count-and-say sequence is the sequence of integers with the first five terms as following: 1 1

QxQ_Alter的博客 290

Count and Say - LeetCode

目录 题目链接 注意点 解法 小结 题目链接 Count and Say - LeetCode 注意点 输入的序列可能小于等于0 解法 解法一:观察题目给的序列,加上网上的评论,可以看出从第二个序列开始,每个序列是对前一个序列的报数。例如,前一个序列是1211,那...

weixin_30840573的博客 154

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 11 21 1211 111221 1 is read off as “one 1” or 11. 11 is read off as “two

hzw2945的博客 294
上一篇: LeetCode解题报告--Remove Element
下一篇: LeetCode解题报告--Next Permutation
YatKam
博客等级 码龄12年 58粉丝 49原创
评论 1
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值