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. python 在头文件添加 #include \"stdafx.h\"\r\n

    import osimport shutil#-*- coding:cp936 -*-import codecsfrom sys import argv def replace_all_files(p ...

  2. ARM体系结构总结

    特殊功能寄存器与外设绑定,通用寄存器是与CPU绑定. ARM是RISC架构 常用ARM汇编指令只有二三十条 ARM是低功耗CPU ARM的架构非常适合单片机.嵌入式.尤其是物联网领域:而服务器等高性能 ...

  3. 多态、Object类和 JDK常用封装类型

    多态 定义:某一类事物的多种存在形态. 多态的体现:父类的引用指向了自己的子类对象.父类的引用也可以接收自己的子类对象. 多态的前提:必须是类与类之间有关系,要么继承,要么实现.通常还有一个前提,存在 ...

  4. L133

    The U.S. Food and Drug Administration is considering a ban on flavorede-cigarettes in response to an ...

  5. Django和pymysql搭建学员管理系统

    学员管理系统 项目规划阶段 项目背景 近年来老男孩教育的入学学员数量稳步快速增长,传统的excel统计管理学员信息的方式已经无法满足日渐增长的业务需求.因此公司急需一套方便易用的“学员管理系统”,来提 ...

  6. java svnkit实现svn提交,更新等操作

    官网:https://svnkit.com/ api:https://svnkit.com/javadoc/org/tmatesoft/svn/core/io/SVNRepository.html w ...

  7. RPi 3.5寸 电阻屏

    /***************************************************************************** * RPi 3.5寸 电阻屏 * 说明: ...

  8. python学习之多线程(一)

    引入线程包或者命名空间import threading 一:建立一个简单的线程程序 import time, threading def test():    print('thread %s is ...

  9. 【英语】Bingo口语笔记(87) - 不要做某事的常见表达

  10. Docker从入门到安装MySQL

    Docker 的简介 Docker 是一个开源的应用容器引擎,基于 Go 语言 并遵从Apache2.0协议开源. Docker 可以让开发者打包他们的应用以及依赖包到一个轻量级.可移植的容器中,然后 ...