본문 바로가기

java

(4)
[Codillity] PermMissingElem 문제 An array A consisting of N different integers is given. The array contains integers in the range [1..(N + 1)], which means that exactly one element is missing. Your goal is to find that missing element. Write a function: class Solution { public int solution(int[] A); } that, given an array A, returns the value of the missing element. For example, given array A such that: A[0] = 2 A[1] = 3 A[2..
[Codillity]CyclicRotation 문제 An 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 moved to the first place. For example, the rotation of array A = [3, 8, 9, 7, 6] is [6, 3, 8, 9, 7] (elements are shifted right by one index and 6 is moved to the first place). The goal is to rotate array A K times; that is, each eleme..
[Codillity] Binary Gap 문제 A binary gap within a positive integer N is any maximal sequence of consecutive zeros that is surrounded by ones at both ends in the binary representation of N. For example, number 9 has binary representation 1001 and contains a binary gap of length 2. The number 529 has binary representation 1000010001 and contains two binary gaps: one of length 4 and one of length 3. The number 20 has binar..
오버로딩(Overloading) vs 오버라이딩(Overriding) 1. 오버로딩(Overloading) 오버로딩이란 매서드(함수)가 같은 이름을 여러개 정의하고, 매개변수의 유형이나 인자의 수나 다른 경우를 말한다. 이를 이용해 다양한 유형의 호출에 응답할 수 있다. //오버로딩 예시 class Overloading { public int sum(int a, int b) { return a + b; } public int sum(int a, int b, int c) { return a + b +c; } public String sum(String a, String b) { return a + b; } } 2. 오버라이딩(Overriding) 오버라이딩이란 상위 클래스의 매서드와 이름이 같은 함수를 하위 클래스(상속 관계에 있는 클래스)에 재정의하는 것을 말한다. //오..