// you can also use imports, for example:
// import java.util.*; // you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message"); class Solution {
public int solution(int N) {
// write your code in Java SE 8
int tempMod=0;
int length=0;
int posOne=-1;
int step=0;
while(N>0){
tempMod=(N%2);
if(tempMod==1){ if(posOne>=0){
length=(length < (step-posOne-1))?(step-posOne-1):length;
}
posOne=step;
} step++;
N=(N/2);
}
return length;
}
}
public int solution(int[] A) {
// write your code in Java SE 8
int i=0;
int result=0;
while(i<A.length){ result=(result^A[i]);
i++;
}
return result;
}
// you can also use imports, for example:
// import java.util.*; // you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message"); class Solution {
public int[] solution(int[] A, int K) {
// write your code in Java SE 8
int[] newA = new int[A.length];
int i=0;
while(i<A.length){
newA[(i+K)%(A.length)]=A[i];
i++;
} return newA;
}
}

codility的更多相关文章

  1. Codility NumberSolitaire Solution

    1.题目: A game for one player is played on a board consisting of N consecutive squares, numbered from ...

  2. codility flags solution

    How to solve this HARD issue 1. Problem: A non-empty zero-indexed array A consisting of N integers i ...

  3. GenomicRangeQuery /codility/ preFix sums

    首先上题目: A DNA sequence can be represented as a string consisting of the letters A, C, G and T, which ...

  4. *[codility]Peaks

    https://codility.com/demo/take-sample-test/peaks http://blog.csdn.net/caopengcs/article/details/1749 ...

  5. *[codility]Country network

    https://codility.com/programmers/challenges/fluorum2014 http://www.51nod.com/onlineJudge/questionCod ...

  6. *[codility]AscendingPaths

    https://codility.com/programmers/challenges/magnesium2014 图形上的DP,先按照路径长度排序,然后依次遍历,状态是使用到当前路径为止的情况:每个 ...

  7. *[codility]MaxDoubleSliceSum

    https://codility.com/demo/take-sample-test/max_double_slice_sum 两个最大子段和相拼接,从前和从后都扫一遍.注意其中一段可以为0.还有最后 ...

  8. *[codility]Fish

    https://codility.com/demo/take-sample-test/fish 一开始习惯性使用单调栈,后来发现一个普通栈就可以了. #include <stack> us ...

  9. *[codility]CartesianSequence

    https://codility.com/programmers/challenges/upsilon2012 求笛卡尔树的高度,可以用单调栈来做. 维持一个单调递减的栈,每次进栈的时候记录下它之后有 ...

  10. [codility]CountDiv

    https://codility.com/demo/take-sample-test/count_div 此题比较简单,是在O(1)时间里求区间[A,B]里面能被K整除的数字,那么就计算一下就能得到. ...

随机推荐

  1. java——二叉树面试题

    import java.util.ArrayList; import java.util.Iterator; import java.util.LinkedList; import java.util ...

  2. 我的Java修养

    无论如何我都会以这种方式严于律己,如有错误接受修正. 1.戒掉对友情和爱情的幻想 2.针对人的行为进行分析,而不是其语言 3.解决一个问题,这个问题会成为解决后续问题的基础和前提 4.不要炫耀,自负, ...

  3. innerHTML动态添加html代码和脚本兼容性问题处理方法

    给某个元素的innerHTML赋值,并使得值中的js代码有效(兼容多个浏览器) 症状:给某个元素的 innerHTML 设置值时,如果提供的 HTML 代码中包含js脚本,很多时候这些脚本无效,或者在 ...

  4. 2017.9.21 HTML学习总结---多媒体播放系统设计

    1.题目:整个页面被划分三个子窗口,上面窗口为页面功能提示区, 下左部分为不同类型播放的功能选项,下右部分为播放系统显示播放信息窗口. (1)网页设计框架: <html> <head ...

  5. 中期ppt制作

    陀螺仪的使用解释:https://zhuanlan.zhihu.com/p/29244429 手机坐标轴的图片:http://jcjs.siat.ac.cn/ch/reader/create_pdf. ...

  6. cityscape分割3类别数据处理

    cpp: #include "cv.h" #include "highgui.h" #include <iostream> #include < ...

  7. EF中 实现延迟加载 lazyload

    1.创建数据库 2.利用数据库 生成视图 生成2个实体类 和一个model1类 3.写代码 (1) 创建 上下文对象 (2) (3)查询结果 注释: 延迟加载的原因,因为我们操作数据库不会那么简单, ...

  8. 爬虫学习(十九)——Scrapy的学习及其使用

    Scrapy框架的介绍 Scrapy,非常的强悍,通过python语言编写的,非常知名的爬虫框架 框架工作流程 框架流程图 基本工作流程; 1.引擎向spiders要url 2.引擎将要爬取的url给 ...

  9. MySQL 5.7传统复制到GTID在线切换(一主一从)

    Preface       Classic replication is commonly used in previous version of MySQL.It's really tough in ...

  10. TCPIP协议编程:基于UDP协议的局域网聊天工具的研发

    任务目标 聊天器采用客户端/服务器(C/S)模式: 客户端利用UDP与服务器相连,客户端与客户端之间通过UDP相互通信: 服务器端具有服务器端口设置维护客户端个人信息,记录客户端状态,分配账号等: 客 ...