LeetCode力扣之Count and Say

从IR Drop到EM分析:数字IC电源规划中那些没人明说的细节(以MTCMOS配置为例) 本文深入探讨数字IC后端设计中电源规划的关键细节,特别关注MTCMOS配置、电源网络电阻最小化和level shifter供电等实战技巧。通过分析IR Drop和EM问题,提供优化floorplan和powerplan的具体策略,帮助工程师避免常见陷阱,提升芯片设计的稳定性和可靠性。 阅读详情

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 "two 1s" or 21.
21 is read off as "one 2, then one 1" or 1211.

Given an integer n, generate the nth term of the count-and-say sequence.

Example 1:

Input: 1
Output: "1"

Example 2:

Input: 4
Output: "1211"
/**
 * Created by lxw, liwei4939@126.com on 2018/3/6.
 */
public class L038_Count_and_Say {

    public String countAndSay(int n){
        String init = "1";
        for (int i = 1; i< n; i++){
            init = countAndSay(init);
        }

        return init;
    }

    String countAndSay(String str){

        char[] arr = str.toCharArray();
        String res = "";

        int index = 1;
        int count = 1;
        char last = arr[0];

        for (; index < arr.length; index++){

            if (arr[index] == last){
                count++;
            }else {
                res += "" + count + last;
                count = 1;
                last = arr[index];
            }
        }
        res += "" + count + last;
        return res;
    }

    public static void main(String[] args){
        L038_Count_and_Say tmp = new L038_Count_and_Say();
        int num = 4;
        System.out.println(tmp.countAndSay(num));
    }
}

Hcaptcha验证码破解深度解析:从环境检测到n值算法的攻防实战 本文深入解析Hcaptcha验证码的攻防技术,从环境检测到n值算法的全面突破策略。详细介绍了浏览器指纹模拟、图像识别工程化解决方案及协议层逆向分析,为安全研究人员提供高效破解Hcaptcha的实战指南。 阅读详情

相关推荐

ESP32小车DIY:从零搭建无线遥控智能车(附完整代码与避坑指南)

本文详细介绍了如何从零开始DIY一台基于ESP32的无线遥控智能小车。内容涵盖核心硬件选型、电路设计、低延迟ESP-NOW无线通信协议的配置与实战,以及双电机差速控制算法与PWM调速的实现。文章提供了完整的代码示例和关键的避坑指南,旨在帮助开发者快速构建稳定可靠的智能车平台,并为进一步的功能扩展奠定基础。

gamma的博客 473

JavaScript 外观数列

给定一个正整数 n ,输出外观数列的第 n 项。 「外观数列」是一个整数序列,从数字 1 开始,序列中的每一项都是对前一项的描述。 你可以将其视作是由递归公式定义的数字字符串序列: countAndSay(1) = "1" countAndSay(n) 是对 countAndSay(n-1) 的描述,然后转换成另一个数字字符串。 前五项如下: 1. 1 2. 11 3. 21 4. 1211 5. 111221 第一项是数字 1 描述前一项,这个...

wanghongpu9305的博客 504

数电实训:万年历

万年历

Lmyccq的博客 1万+

LeetCode——报数( Count and Say)

题目: 报数序列是指一个整数序列,按照其中的整数的顺序进行报数,得到下一个数。其前五项如下: 1. 1 2. 11 3. 21 4. 1211 5. 111221 1 被读作  "one 1"  ("一个一") , 即 11。11 被读作 "two 1s" ("两个一"), 即 21。21 被读作 "one 2",  "one 1" (&q

qq_23418043的博客 983

变色龙哈希函数 Chameleon Hash 可变型区块链

哈希函数 Hash: 众所周知,区块链有着极其优秀的安全性就是因为其充分使用了哈希函数。 哈希简单用一句话来讲,就是:将任意长度输入的字串可转换成一个固定长度的字串,通过原始字串可以很容易地算出转换后的字串,通过转换后的字串很难还原出原始字串。 哈希函数特征: 1. 对于任意m作为输入,得到输出的结果,很难找到另一个输入m'  (m'不等于m),使得m'的Hash结果也为同样的输出

新手村 1万+

RK3588设备树调试实战:解决NPU不加载、USB3.0识别异常与DP显示问题

本文深入探讨了RK3588设备树调试中的三大典型问题:NPU不加载、USB3.0识别异常与DP显示问题。通过详细的问题定位步骤、关键设备树修改和调试技巧,帮助开发者快速解决硬件适配中的挑战,提升RK3588平台的开发效率。

weixin_30576827的博客 483

38. Count and Say【力扣】

题意理解 报数,个数和数字拼成新的字符串。 问题分析 字符串,遍历循环处理,双指针 string countAndSay(int n) { string str = "1", newStr; if (n == 1) return "1"; while(--n) { ne...

xiexie1357的专栏 192

【异常】安装hermes-agent时提示GnuTLS recv error (-110): The TLS connection was non-properly terminated.

Git克隆仓库时出现TLS连接异常报错的解决方案摘要: 当执行git clone命令时遇到"GnuTLS recv error (-110)"报错,通常由网络不稳定、缓冲区不足或证书验证问题导致。主要解决方案包括:1)增大Git HTTP缓冲区(git config --global http.postBuffer 524288000);2)使用GitHub镜像站加速克隆;3)临时禁用SSL验证进行测试;4)检查并调整代理配置;5)改用SSH协议克隆。建议优先尝试增大缓冲区和镜像站方案,

奶爸的编程之路,也就一周冷个三天 1360

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

慢慢积累 1265

把 SAP Activate 六个阶段看透:从项目落地到 SAP BTP 扩展与 AI 运营的一体化实践

摘要: SAP Activate 方法论常被误解为简单的项目阶段划分,实则是一套将业务目标、标准流程、系统配置和持续运营串联的实施控制体系。其六个阶段(Discover至Run)构成价值递进的实施通道,核心交付集中在Prepare到Deploy阶段。Discover阶段通过DDA评估确立项目方向与范围,Prepare阶段聚焦可执行性准备,Explore阶段采用Fit-to-Standard工作坊进行需求分层,Realize阶段基于前期决策进行配置与扩展开发。该方法论强调标准化优先,差异化需求通过SAP BT

2007 年 ~ 2025 年,深耕 SAP 技术 18 年 2342

验证 helm Chart 的正确性

验证 helm Chart 的正确性

小橙子的笔记屋 282

LeetCode Count and Say 解题报告

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

算法的天空 1万+

Vibe Draw:AI实现2D草图转3D建模,开源免费的设计师宝藏软件!

AI实现2D草图转3D建模,开源免费,设计师进来看一下?

Code_流苏:在代码中寻诗意,在实践中觅真知 2160

LeetCode力扣 38. 外观数列 Count and Say 题解代码 JavaScript

https://leetcode-cn.com/problems/count-and-say/ /** * @param {number} n * @return {string} */ var countAndSay = function(n) { var s = "1" ,i,j, str; var t1,ts; for(i=1;i<n;++i) { t1 = 1; ts = s[0]; str = "";

Coding home - 漂流瓶jz 606

Statistics and Machine Learning Toolbox

Statistics and Machine Learning Toolbox(带书签),MATLAB统计学习工具

复分析 阿尔福斯(Ahlfors) 第三版答案 英文

答案分为十章,有部分习题没有答案,全英文复分析阿尔福斯(Ahlfors) 第三版答案

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

怀旧版电脑GBC模拟器

再现原版GBC掌机的界面,电脑运行连游戏界面都一样大小,很怀旧,很真实,(英文版)强烈推荐,很小的文件,很难才找到的。

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

Devexpress16.2.6破解工具

Devexpress16.2.6破解工具Devexpress16.2.6破解工具Devexpress16.2.6破解工具Devexpress16.2.6破解工具

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

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

[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 779

[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的博客 486

leetcode 38. Count and Say

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

编码之路 369

[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的博客 210

《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-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的专栏 435

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的博客 690
上一篇: LeetCode力扣之Search Insert Position
下一篇: LeetCode总结
Lee_Wei4939
博客等级 码龄11年 114粉丝 184原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值