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. language model ——tensorflow 之RNN

    代码结构 tf的代码看多了之后就知道其实官方代码的这个结构并不好: graph的构建和训练部分放在了一个文件中,至少也应该分开成model.py和train.py两个文件,model.py中只有一个P ...

  2. uboot配置过程详解1

    x210_sd_config : unconfig @$(MKCONFIG) $(@:_config=) arm s5pc11x x210 samsung s5pc110 @echo "TE ...

  3. UIPickerView/UIDatePicker/程序启动的完整过程

    一.UIPickerView 1.UIPickerView的常见属性 数据源(用来告诉UIPickerView有多少列多少行) @property(nonatomic,assign) id<UI ...

  4. 接口取不到POST参数

    利用类似httprequester小工具调试API时偶尔出现一直取不到POST的数据 解决方式: 1.$_POST['paramName']: 只能接收Content-Type: applicatio ...

  5. C# 中字段和属性的使用时机

    在C#中,我们可以非常自由的.毫无限制的访问公有字段,但在一些场合中,我们可能希望限制只能给字段赋于某个范围的值.或是要求字段只能读或只能写,或是在改变字段时能改变对象的其他一些状态,这些单靠字段是无 ...

  6. aac adts & LATM封装码流分析

    本文继续上一篇文章的内容,介绍一个音频码流处理程序.音频码流在视频播放器中的位置如下所示. 本文中的程序是一个AAC码流解析程序.该程序可以从AAC码流中分析得到它的基本单元ADTS frame,并且 ...

  7. android官网被封掉了,只好用这个网站进谷歌了!嘎嘎

         http://developer.android.com/sdk/index.html    这个可以进去,但是必须是搜狐 .360,uc都不用特意FQ     http://173.1 ...

  8. Python 把二进制mnist数据库转换为图片

    mnist数据库可以通过caffe里的get_mnist.sh文件下载,路径是: caffe-master/data/mnist/get_mnist.sh,get_mnist.sh内容如下: #!/u ...

  9. Linux 工具套件 —— binutils、readelf

    readelf:Linux 下专门针对 ELF 文件格式的解析器: 0. binutils GNU Binutils gnu binutils 一套二进制工具的集合,主要包含:ld(gnu linke ...

  10. PHPExcel导出导入

    便于记忆 这里写一个PHPexcel导出的demo 我们构造一个数据   $letter = array('A','B','D','E'); //sheet索引   $date = array( ar ...