GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • 注册
  • Plus 会员

This view

  • Original page
  • New address

GeezerVison is showing leetcode.cn — 481. 神奇字符串 - 力扣(LeetCode)

题目描述
题目描述
题解
题解
提交记录
提交记录
481. 神奇字符串
中等

神奇字符串 s 仅由 '1' 和 '2' 组成,并需要遵守下面的规则:

  • 将连续相同字符组 '1' 和 '2' 长度的序列连接起来会生成字符串 s 本身。

s 的前几个元素是 s = "1221121221221121122……" 。如果将 s 中连续的若干 1 和 2 进行分组,可以得到 "1 22 11 2 1 22 1 22 11 2 11 22 ......" 。每组中 1 或者 2 的出现次数分别是 "1 2 2 1 1 2 1 2 2 1 2 2 ......" 。上面的出现次数正是 s 自身。

给你一个整数 n ,返回在神奇字符串 s 的前 n 个数字中 1 的数目。

 

示例 1:

输入:n = 6
输出:3
解释:神奇字符串 s 的前 6 个元素是 “122112”,它包含三个 1,因此返回 3 。 

示例 2:

输入:n = 1
输出:1

 

提示:

  • 1 <= n <= 105
 
代码
代码
测试用例
测试用例
测试结果
测试结果
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.