Skip to content

Instantly share code, notes, and snippets.

View kninami's full-sized avatar

kyungsuk CHO kninami

View GitHub Profile
@kninami
kninami / binary-gap.java
Created October 20, 2016 04:35
Codility Solution-binary gap
import java.util.ArrayList;
class Solution{
public int solution(int N){
ArrayList<Integer> array = new ArrayList<Integer>();
int count = 0;
int max = 0;
boolean flag = false;
import java.util.*;
import java.lang.*;
import java.util.Arrays;
class Solution {
public int solution(int N) {
int N3 = 1;
String bina = Integer.toBinaryString(N);
String pro[] = bina.split("0");
int[] score = new int[pro.length];
import java.util.*;
class Solution {
public int solution(int[] A) {
Map<Integer,Integer> matchMap = new HashMap<Integer,Integer>();
int unPaired = 0;
for(int i=0;i<A.length;i++){
int value = matchMap.get(A[i])==null?0:matchMap.get(A[i]);
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map.Entry;
class Solution {
public int solution(int[] A) {
int result=0;
HashMap<Integer , Integer> map = new HashMap<Integer , Integer>();
for(int i=0;i<A.length;i++){
function solution(A) {
let solver = {
makeCounterHash: (A) => {
let counterMap = {};
const ARR_LEN = A.length;
const HALF_IDX = Math.floor(ARR_LEN / 2);
for (let idx = 0; idx <= HALF_IDX; idx++) {
const prenum = A[idx];
if (counterMap.hasOwnProperty(prenum)) {
/*
node로 실행
풀이 방식
시간 복잡도를 O(n)으로 하기 위해 bit연산으로 하여 처리
10진수 값을 1과 AND 연산해서 2진수의 역순으로 하나씩 꺼내서 처리
*/
function solution(N) {
let curNum = N;
let maxZeroCnt = 0;
class Solution {
public int[] solution(int[] A, int K) {
int[] B = new int[A.length];
for(int i=0; i<A.length; i++){
B[(i+K)%A.length] = A[i];
}
return B;
}
class Solution {
public int[] solution(int[] A, int K) {
int[] result = new int[A.length];
int length = 0;
if(K!=0 && A.length!=0){ length = K%A.length; }
for(int i=0;i<A.length;i++){
if(i+length<A.length){
result[i+length] = A[i];
}else{
class Solution {
public int solution(int[] A) {
long N = A.length +1;
long totalSum = (N*(N+1))/2;
for(int i=0; i<A.length; i++){
totalSum -= A[i];
}
return (int)totalSum;
function solution(A) {
const sum = (A.length + 1) * (A.length + 1 + 1) / 2;
return A.reduceRight((prev, cur) => prev - cur, sum);
}