codility
2024-10-22 11:00:51
// 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;
}
}
最新文章
- Java服务器对外提供接口以及Android端向服务器请求数据
- 三:关于tcp
- 《Pro Express.js》学习笔记——概述
- OpenCV阶段总结扩充。
- PRML读书会第三章 Linear Models for Regression(线性基函数模型、正则化方法、贝叶斯线性回归等)
- POJ-2886 Who Gets the Most Candies?(线段树+模拟)
- Coder-Strike 2014 - Round 1(A~E)
- 控制反转(IoC)与依赖注入(DI)
- HDU 1394 Minimum Inversion Number (数据结构-段树)
- wcf例子01
- unity3dWeb版文本转语音
- php 执行效率
- Bootstrap3写的红色警告框样式组件
- 【原】使用IDEA创建Maven工程时提示";...xxx/pom.xml already exists in VFS";的解决
- C#十进制与任意进制的转换
- 你好,我是梁桐铭,.NET程序员,啰嗦下过去几年来的感悟吧
- Flask-WTF中的csrf保护
- cordova打包vue2(webpack)android、ios app
- 梯度下降法的三种形式BGD、SGD以及MBGD
- linux 下的常用操作命令