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 ...
随机推荐
- opencv:傅里叶变换
示例代码: #include <opencv.hpp> #include <iostream> using namespace std; using namespace cv; ...
- 016——VUE中v-show的使用与v-if的差异对比
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...
- 【2018年全国多校算法寒假训练营练习比赛(第五场)-C】字符串问题(KMP)
题目链接:https://www.nowcoder.com/acm/contest/77/C [题意] 求一个字符串中最长的子串,要求子串既是原串的前缀又是后缀,除前后缀还在中间出现过. [思路] K ...
- LeetCode OJ:Remove Duplicates from Sorted Array(排好序的vector去重)
Given a sorted array, remove the duplicates in place such that each element appear only once and ret ...
- 原创:Javascript DI!Angular依赖注入的实现原理
DI是Angular的特色功能,而在Angular 2.0的计划中,DI将成为一个独立的模块,参见 https://github.com/angular/di.js 这意味着它也有机会被用于nodej ...
- python学习网址
http://kuanghy.github.io/categories/#Python
- 【解题报告】[动态规划]RQNOJ - PID82 / 又上锁妖塔
原题地址:http://www.rqnoj.cn/problem/82 解题思路: 简单的动态规划 状态表示:DP[i][0]表示当前在第i层,且当前跳跃状态不可用,此时消耗的最短时间. DP[i ...
- 深入理解vsto,开发word插件的利器
开发了vsto,客户那边也有一些反映插件安装失败或者加载不上的情况.于是我下定决定再理解下vsto的工作机制,如下图: 如上图所示,我把vsto的解决方案分为两部分,一部分是vsto Add-ins, ...
- LeetCode Max Stack
原题链接在这里:https://leetcode.com/problems/max-stack/description/ 题目: Design a max stack that supports pu ...
- LeetCode Optimal Division
原题链接在这里:https://leetcode.com/problems/optimal-division/description/ 题目: Given a list of positive int ...