Skip to content

Instantly share code, notes, and snippets.

View mateusmarquezini's full-sized avatar
:octocat:

Mateus Marquezini mateusmarquezini

:octocat:
View GitHub Profile
@mateusmarquezini
mateusmarquezini / Solution.java
Created April 19, 2016 12:05
CyclicRotation - Codility
/**
* A zero-indexed array A consisting of N integers is given. Rotation of the array means that each element is shifted right by one index, and the last element of the array is also moved to the first place.
For example, the rotation of array A = [3, 8, 9, 7, 6] is [6, 3, 8, 9, 7]. The goal is to rotate array A K times; that is, each element of A will be shifted to the right by K indexes.
Write a function:
class Solution { public int[] solution(int[] A, int K); }
that, given a zero-indexed array A consisting of N integers and an integer K, returns the array A rotated K times.
@mateusmarquezini
mateusmarquezini / Solution.java
Created September 21, 2016 13:46
Codility Distinct problem - Java Solution
import java.util.Arrays;
/**
* Created by mateus marquezini on 09-09-2016.
*/
public class Solution {
public int solution(int[] A) {
int count = 1;
@mateusmarquezini
mateusmarquezini / BinarySearch.kt
Created April 28, 2017 18:54
Binary Search in Kotlin
package binarySearch
import java.util.*
/**
* Created by Mateus Marquezini on 28/04/2017.
*/
class BinarySearch
fun main(args: Array<String>){
let mapa = new Map()
function ler(){}
const carro = {}
mapa.set("texto", "A chave é do tipo string")
mapa.set(2, "A chave é do tipo numérico")
mapa.set(ler, "A chave é uma função")
mapa.set(carro, "A chave é um objeto")
console.log(mapa.get(“texto”)) // "A chave é do tipo string"
console.log(mapa.get(2)) // "A chave é do tipo numérico"
console.log(mapa.get(ler)) // "A chave é uma função"
console.log(mapa.get(carro)) // "A chave é um objeto"
console.log(mapa.size) // 4
console.log(mapa.has("texto")) // true
console.log(mapa.has(2)) // true
console.log(mapa.has("Olá, mundo!")) // false
console.log(mapa.has(5)) // false
mapa.delete(2)
console.log(mapa.has(2)) // false
for(let chave of mapa.keys()){
console.log(chave)
}
for(let valor of mapa.values()){
console.log(valor)
}