LeetCode--038--报数(java)】的更多相关文章

38. 报数 水题 class Solution { public String next(String num) { String ans = ""; int i = 0; while (i < num.length()) { char ch = num.charAt(i); int cnt = 0; while (i < num.length() && ch == num.charAt(i)) { i++; cnt++; } ans += cnt; an…
索引:[LeetCode] Leetcode 题解索引 (C++/Java/Python/Sql) Github: https://github.com/illuz/leetcode 038. Count and Say (Easy) 链接: 题目:https://leetcode.com/problems/Count-and-Say/ 代码(github):https://github.com/illuz/leetcode 题意: 数数.第一个是 1,第二个是数前一个数:1 个 1,就是 11…
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…
输入1个数字和多个字符,中间均以空格隔开.假设数字取值为m(范围1~9),后面字符个数为n.假设n个字符围成一圈,从第一个字母开始循环报数,当数到m以后,第m个字母就出列,直到这n个字母全部出列.最后,按照出列的顺序输出这些字母,中间仍以空格隔开.取值范围:m为1到9, 字符个数n大于1小于20. 网上很多方法感觉好乱,很多所谓的Java都是根据c的思想完成的没有Java的灵活性. 附代码: import java.util.*; public class Recycle { static Sc…
leetcode 237. 删除链表中的节点 链接:https://leetcode-cn.com/problems/delete-node-in-a-linked-list/ 示例 : 输入: head = [4,5,1,9], node = 5输出: [4,1,9]解释: 给定你链表中值为 5 的第二个节点,那么在调用了你的函数之后,该链表应变为 4 -> 1 -> 9. 这道题比较简单,修改之前节点的 next 指针,使其指向之后的节点: /** * Definition for sin…
报数序列是一个整数序列,按照其中的整数的顺序进行报数,得到下一个数.其前五项如下: 1. 1 2. 11 3. 21 4. 1211 5. 111221 1 被读作 "one 1" ("一个一") , 即 11. 11 被读作 "two 1s" ("两个一"), 即 21. 21 被读作 "one 2", "one 1" ("一个二" , "一个一"…
整体思路同之前的一样,依然采取降低维度的方式进行 public List<List<Integer>> solution(int nums[], int target) { List<List<Integer>> result = new ArrayList<>(); if((nums.length<4)||(nums==null)) { return result; } Arrays.sort(nums); if ((4*nums[0]&…
题目在这里: https://leetcode.com/problems/3sum/ [标签] Array; Two Pointers [个人分析] 老实交待,这个题卡半天,第一次做不会,抄别人的.过了很久,第二次做,还是不会…….好几次都是Time Limited Error.在看过正确答案之后,才知道是用的Two Pointers + sort 做的优化. 怎么优化? 简单说,就是通过 排序 + 跳过重复(利用Two Pointers) 来达到题目中避免 duplicates的要求. 核心思…
Problem Design and implement a data structure for Least Recently Used (LRU) cache. It should support the following operations: get and set. get(key) - Get the value (will always be positive) of the key if the key exists in the cache, otherwise return…
题目 Given an array of integers, every element appears three times except for one. Find that single one. Note: Your algorithm should have a linear runtime complexity. Could you implement it without using extra memory? 给定一个整型数组,每个数都出现了三次(只有一个数只出现了一次),找到…