public class Solution {
public int MagicalString(int n) {
if (n <= ) return ;
if (n <= ) return ; int[] a = new int[n + ];
a[] = ; a[] = ; a[] = ;
int head = , tail = , num = , result = ; while (tail < n)
{
for (int i = ; i < a[head]; i++)
{
a[tail] = num;
if (num == && tail < n)
{
result++;
}
tail++;
}
num = num ^ ;//异或
head++;
} return result;
}
}

https://leetcode.com/problems/magical-string/#/description

leetcode481的更多相关文章

  1. [Swift]LeetCode481. 神奇字符串 | Magical String

    A magical string S consists of only '1' and '2' and obeys the following rules: The string S is magic ...

随机推荐

  1. input预览上传图片

    html代码 <input type="file" name="file" id="file" > <img src=&q ...

  2. LeetCode OJ:Recover Binary Search Tree(恢复二叉搜索树)

    Two elements of a binary search tree (BST) are swapped by mistake. Recover the tree without changing ...

  3. 《Java程序员职场全攻略 从小工到专家》 - 书摘精要

    (前言) 学习招式在次,提升内力才是最主要的: (P10) 选择一门编程语言,只是入门的途径.过分依赖编程语言,只会让自己成为代码高手,而不是开发大牛,要知道编程语言只是一种工具,更重要的是编程思想: ...

  4. 登录页面jsp跳转到另一个jsp 与jsp-Servlet-jsp

    登录页面jsp 到另一个jsp,与jsp-Servlet-jsp  都是可以从表单提交参数信息. 但是jsp-jsp ,只能通过<%=request.getParameter("use ...

  5. 【linux】基础知识学习

    [版本] 两种:内核版本 . 发行版本 内核版本从 www.kernel.org 查看 发行版本: 1.retHat, centOS 更稳定,更安全,适宜做企业服务器 2.ubuntu, Debian ...

  6. 记录下jplayer的简单demo

    jplay一个播放器的工具包,依赖于jquery或者zepto,有zepto所以相当于是PC和移动都支持. 它的官方文档为:http://www.jplayer.cn/ 同时也推出的react的支持包 ...

  7. 前端之JavaScript 03

    window对象 所有浏览器都支持 window 对象.概念上讲.一个html文档对应一个window对象.功能上讲: 控制浏览器窗口的.使用上讲: window对象不需要创建对象,直接使用即可. W ...

  8. CALayer 实现的动画效果(一)

    先看下效果图: (备注: 上面GIF 是Mac 下录制视频的并转化成gif 的而成,工具为GIF Brewery 3 [这款软件挺不错的]) 那么主题来了如何实现上面效果呢? 1.创建自定义CALay ...

  9. 转载 eclipse中的include设置

    备注:在10.1版的niosii使用的eclipse中设置的方法是右键->properties->c/c++general->path and symbols->include ...

  10. 【java规则引擎】drools6.5.0中kie的概论

    什么是KIE? KIE是jBoss里面一些相关项目的统称,下图就是KIE代表的一些项目,其中我们比较熟悉的就有jBPM和Drools. 这些项目都有一定的关联关系,并且存在一些通用的API,比如说涉及 ...