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 ...
随机推荐
- 【scala】异常处理
Scala 的异常处理和其它语言比如 Java 类似. 抛出异常 Scala 抛出异常的方法和 Java一样,使用 throw 方法 throw new IllegalArgumentExceptio ...
- 星火计划ROS机器人Spark
星火计划ROS机器人Spark 1 http://wiki.ros.org/Robots/Spark 2 https://github.com/NXROBO/spark ---- Spark Spar ...
- Mac上安装Jenkins持续部署初体验
1.首先去官网下载安装包 https://jenkins.io/doc/book/installing/ 安装完成后,很不幸,无法访问他的默认站点 查了一堆资料,有的说环境变量没有配置,有的说没有执行 ...
- 前端之jQuery02
文档操作 重点:创建标签,jQuery里面没有这个方法 内部(子标签) 添加到指定元素内部后面 $(A).append(B): // B作为A的最后一个儿子元素:(把B追加到A) $(A).appen ...
- bzoj 4555 求和
求 $\sum\limits_{i=0}^n\sum\limits_{j=0}^n Stirling2(i,j) \times 2^j \times j!$ $n \leq 100000$ sol: ...
- leetcode_sql_3,181,182,183
181. Employees Earning More Than Their Managers The Employee table holds all employees including the ...
- vs2015 c++ _findnext 报错
定位 _findnext(hFile,&fileinfo) 报错. 错误 :0x00007FFC70CB0B2D (ntdll.dll)处(位于 Cutton_Dlg.exe 中)引发的异常: ...
- FTP上传失败报错227 Entering Passive Model (222,111,8,111,10,40)
昨天为了一个ftp问题折腾了一天.问题背景:原来有个接口涉及到上传文件,服务端更换了ftp服务器,我们这边需要刷新连接服务端的ip和端口配置,代码没动.联调环境和验收环境都测试通过,一到生产环境就歇菜 ...
- PAT1018——最短路加DFS
http://pat.zju.edu.cn/contests/pat-a-practise/1018 在杭州各个点,有很多自助自行车的点,最大容纳点为CMAX,但比较适合的情况是CMAX/2, 现在从 ...
- android中状态栏透明
设置 Acitivity 所在 window 的属性 @Override protected void onCreate(Bundle savedInstanceState) { super.onCr ...