38. Count and Say Problem's Link ---------------------------------------------------------------------------- Mean: 题目意思太晦涩. 1 读出来 就是“1个1” 所以记为“11” 11 读出来 就是“2个1” 所以记为“21” 21 读出来 就是“1个2 1个1” 所以记为“1221” .... analyse: 略. Time complexity: O(N) view code…
题目链接:https://leetcode.com/problems/count-and-say/?tab=Description   1—>11—>21—>1211—>111221—>312211—>….   按照上面的规律进行求解出第n个字符串是什么.   规律:相连的数字有多少个然后添加上这个数字   参考代码:    package leetcode_50; /*** * * @author pengfei_zheng * 按照规律进行求解字符串 */ publ…
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…
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…
这道题主要就是求一个序列,题目得意思就是 1 --> 11 --> 21 --> 1211 -->   111221 --> 312211 --> ..... 1个1     2个1     1个2,1个1   1个1,1个2,2个1  3个1,2个2,1个1 依次类推 题目很简单,但是为了得到较好的结果,还是纠结了一段时间 public class countAndSay { public String countAndSay(int n) { String num…
题目描述: 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.…
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…
class Solution { public: vector<string> vs_; Solution(){ "); vs_.push_back(t); ; i< ;++i){ ]; t = ""; ,j ; ; j < t1.size() - ; ++j){ ]){ ++cnt; } else{ ] =""; sprintf(s,"%d%c",cnt,t1[j]); t += string(s); cnt…
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…
1.题目 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 off as "two 1s" or 21.21 is read off as …
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 read off as "one 2, then one 1&quo…
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 read off as "one 2, then one 1" …
一 字符串 1.不可变String String对象是不可变的,查看JDK文档你就会发现,String类中每一个看起来会修改String值的方法,实际上都是创建一个全新的String对象,以包含修改后的字符串内容.而最初的String对象则没有改变. 看看下面的代码: public class Immutable { public static String upcase(String s) { return s.toUpperCase(); } public static void main(…
Leetcode:003 无重复字符串 关键点:给定一个字符串,请你找出其中不含有重复字符的 最长子串 的长度.示例 1:输入: "abcabcbb"输出: 3 解释: 因为无重复字符的最长子串是 "abc",所以其长度为 3.示例 2:输入: "bbbbb"输出: 1解释: 因为无重复字符的最长子串是 "b",所以其长度为 1.示例 3:输入: "pwwkew"输出: 3解释: 因为无重复字符的最长子串是…
作者:CYC2018 文章链接:https://github.com/CyC2018/CS-Notes/blob/master/docs/notes/Leetcode+%E9%A2%98%E8%A7%A3.md 本文主要介绍的是LeetCode题库中与字符串相关的经典题目,提供了LeetCode原题题号,参考答案,以及题目的部分解析. 大家可以参考这个刷题指南来完成对字符串部分题目的练习,当然,这只是一部分,字符串的相关题目还有很多,譬如最长公共子序列和最长公共子串,这里列举的只是LeetCod…
题意:有一个长度为\(n\)的字符串,你可以选取一个值\(k(1\le k \le n)\),然后遍历字符串,每次将区间长度为\(k\)的字符串反转,求反转后字典序最小的字符串,并输出\(k\)的值. 题解:这题我是打表找规律写的,观察样例不难发现,当区间长度为\(k\)时,答案字符串就是将前\(k-1\)个字符移到了尾部,并且,假如\(k\)的奇偶性和\(n\)相同,那么这前\(k-1\)个字符就要反转,所以我们只要遍历\(k\),然后模拟维护一个字典序最小的字符串即可. 代码: int t;…
[python]Leetcode每日一题-扰乱字符串 [题目描述] 使用下面描述的算法可以扰乱字符串 s 得到字符串 t : 如果字符串的长度为 1 ,算法停止 如果字符串的长度 > 1 ,执行下述步骤: 在一个随机下标处将字符串分割成两个非空的子字符串.即,如果已知字符串 s ,则可以将其分成两个子字符串 x 和 y ,且满足 s = x + y . 随机 决定是要「交换两个子字符串」还是要「保持这两个子字符串的顺序不变」.即,在执行这一步骤之后,s 可能是 s = x + y 或者 s =…
2016年12月12日10:00:16 ====================== 网页访问速度的提升,是可以通过代码的优化来实现的.代码的优化,并不是说代码越少越好,而是主要看代码的运行能力和执行效率,看其消耗CPU和内存的多少.例如Facebook近来就宣布通过代码优化而将网站性能提高了一倍,平均访问时间从5s降至2.5s,这个结果无疑是极其诱人的. PHP是一门很多人正在使用的语言,在网站开发上PHP的使用广泛度超过ASP和ASP.NET,看看时下流行的CMS和博客用什么语言来开发的就知…
想获得漂亮的格式化字符串后输出,可以使用json.dumps() 的indent 参数.它会使得输出和pprint() 函数效果类似 >>> data {'age': 4, 'name': 'niuniuche', 'attribute': 'toy'} >>> import json >>> print(json.dumps(data)) {"age": 4, "name": "niuniuche&q…
    •连续输入字符串,请按长度为8拆分每个字符串后输出到新的字符串数组:•长度不是8整数倍的字符串请在后面补数字0,空字符串不处理. 输入描述: 连续输入字符串(输入2次,每个字符串长度小于100) 输出描述: 输出到长度为8的新字符串数组 输入例子: abc 123456789 输出例子: abc00000 12345678 90000000       import java.util.*; public class Main{     public static void main(S…
在其他语言中十分常见的字符串格式化输出,居然在 Javascript 中不见踪影,于是决定自己实现该方法,以下就是个人编写的最简洁实现: String.prototype.format = function(){ var args = arguments; return this.replace(/\{(\d+)\}/gm, function(ms, p1){return typeof(args[p1]) == 'undefined' ? ms : args[p1]}); } 应用示例: >>…
function getLenPx(str, font_size) { var str_leng = str.replace(/[^\x00-\xff]/gi, 'aa').length; return str_leng * font_size / 2 } var a = getLenPx("你好a",20) // a = 50 字符串的像素宽度和字体的大小有关. 单个汉字的像素宽度 等于 字体的大小 字母的像素宽度等于 字体大小的一半 例如: 字体大小为 20px 那么 "…
C语言中以字符串形式输出枚举变量 摘自:https://blog.csdn.net/haifeilang/article/details/41079255 2014年11月13日 15:17:20 haifeilang 阅读数:6295   每个枚举常量对应一个整形数字,很多时候可以像整形一样使用,这个大家都知道:但是如果要求打印枚举变量名的字符串,办法也有很多,查看网上方法几乎都需要转换,要么用数组,下面要说的是一种可以算是直接打印的新方法: #会将后面的内容作为字符串返回 如果想让#后面的内…
static void Main(string[] args) { // 根据用户输入字符串,输出大写字母有几个,小写字母有几个. Console.WriteLine("请输入一行英文代码"); string s = Console.ReadLine(); //用一个字符串接受输入值. int i = 0; int j = 0;// i是大写个数, j是小写个数. foreach (char s1 in s) { if (s1 >= 'A' && s1 <=…
今天碰到一个算法题觉得比较有意思,研究后自己实现了出来,代码比较简单,如发现什么问题请指正.思路和代码如下: 基本思路:从左开始取str的最大子字符串,判断子字符串是否为str的后缀,如果是则返回str加子字符串剩余部分:如果不是则逐步减少子字符串长度后在进行比较./* * 给出一个字符串s,输出包含两个字符串s的最短字符串,如s为abca时,输出则为abcabca */ public class ContainTwoString { public static String MergeStri…
1.echo() echo()实际不是一个函数,是一个语言结构,不需要使用括号 <?php $str = "test"; echo $str."<br>"; //输出test echo $str." of php.<br>"; //使用.连接多个字符串,输出test of php. echo "test","test1","test2"; //输出用逗号多个…
题目内容: 输入两个字符串,输出两个字符串集合的并集. 为保证输出结果一致,请将集合内元素排序之后再输出, 如对于集合aset,可输出sorted(aset). 输入格式: 共两行,每一行为一个字符串 输出格式: 共一行,为一个集合 输入样例: abc bcd 输出样例: ['a', 'b', 'c', 'd'] 时间限制:500ms内存限制:32000kb a = input() b = input() aset = set(a + b) print(sorted(aset))…
字符串的输出使用print语句,在每个语句的输出的时候我们使用' '和" "来包含字符串比如: 如果有多个字符串的话呢我们需要用”,“来进行连接: 我们不仅可以使用字符来进行输出时用”,”来进行链接,还可以将数字和字符串连接在一起:…
字符串: C语言中最有用.最重要的数据类型之一. 字符串:是以\0字符结尾的char类型数组.所以可以把数组和指针知识应用于字符串. 如何在程序定义字符串: 1.字符串字面量 用双引号括起来的内容称为字符串字面量,也叫作字符串常量.双引号中的字符和编译器自动加入末尾的\0字符,都作为字符串储存在内存中. 如果要在字符串内部使用引号,必须要在双引号前面加上一个反斜杠(\). 字符串字面量被视为const,就不能更改了. 字符串常量属于静态存储类别.这说明如果在函数中使用字符串常量,该字符串只会被储…
package com.swift; public class String_To_Integer_Test { public static void main(String[] args) { /* * 编程求字符串“100”和“150”按十进制数值做差后的结果以字符串形式输出. */ String str1="100"; String str2="150"; int i1=Integer.valueOf(str1); int i2=Integer.valueOf…