leetcode481
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的更多相关文章
- [Swift]LeetCode481. 神奇字符串 | Magical String
A magical string S consists of only '1' and '2' and obeys the following rules: The string S is magic ...
随机推荐
- python练习题100例
链接地址:http://www.runoob.com/python/python-100-examples.html
- C#模拟网络POST请求
using System; using System.IO; using System.Net; using System.Text; using System.Collections.Generic ...
- java学习网站推荐
推荐大家一个好的java学习网站: http://www.programcreek.com/java-api-examples/index.php 可以找到api对应的开源项目使用的代码.
- 如何复制一个java对象(浅克隆与深度克隆)
在项目中,有时候有一些比较重要的对象经常被当作参数传来传去,和C语言的值传递不同,java语言的传递都是引用传递,在任何一个地方修改了这个对象的值,就会导致这个对象在内存中的值被彻底改变.但是很多时候 ...
- Android 进阶16:IntentService 使用及源码解析
It's time to start living the life you've only imagined. 读完本文你将了解: IntentService 简介 IntentService 源码 ...
- Android OpenCSV
OpenCSV https://sourceforge.net/projects/opencsv/ 使用参考 http://stackoverflow.com/questions/16672074/i ...
- (二)Vue常用7个属性
学习vue我们必须之到它的7个属性,8个 方法,以及7个指令.787原则 el属性 用来指示vue编译器从什么地方开始解析 vue的语法,可以说是一个占位符. data属性 用来组织从view中抽象出 ...
- 修改Sublime Text3 的侧边栏字体大小
修改Sublime Text3 的侧边栏字体大小 1. 安装”Package Control Package Control”,建议使用官方安装命令:https://sublime.wbond.net ...
- 【英语】Bingo口语笔记(83) - hell系列
- linux rhel7下安装python
1.查看是否已经安装Python Centos7默认安装了python2.7.5 因为一些命令要用它比如yum 它使用的是python2.7.5. 使用python -V命令查看一下是否安装Pytho ...