CodingBat Java: Array-3 (linearIn)
Given two arrays of ints sorted in increasing order, outer and inner, return true if all of the numbers in inner appear in outer. The best solution makes only a single "linear" pass of both arrays, taking advantage of the fact that both arrays are already in sorted order. linearIn([1, 2, 4, 6], [2, 4]) → true linearIn([1, 2, 4, 6], [2, 3, 4]) → false linearIn([1, 2, 4, 4, 6], [2, 4]) → true Solu..
CodingBat Java: Logic-2 (evenlySpaced)
problem - Given three ints, a b c, one of them is small, one is medium and one is large. Return true if the three values are evenly spaced, so the difference between small and medium is the same as the difference between medium and large. evenlySpaced(2, 4, 6) → true evenlySpaced(4, 6, 2) → true evenlySpaced(4, 6, 3) → false Solution 이번 문제는 하나는 가장 작고, 하나는 중간값, 하나는 가장 큰 값으로 구성된 3개의 숫자가 주어진다. 그리고 ..
CodingBat Java: Warmup-2 (noTriples)
problem - Given an array of ints, we'll say that a triple is a value appearing 3 times in a row in the array. Return true if the array does not contain any triples. noTriples([1, 1, 2, 2, 1]) → true noTriples([1, 1, 2, 2, 2, 1]) → false noTriples([1, 1, 1, 2, 2, 2, 1]) → false Solution 이번 문제는 연속된 세 개의 숫자를 가지는 배열일 경우 false를 반환하는 문제이다. 특별한 풀이과정은 없었으며, 배열의 인덱스를 전진하면서 연속된 세 개의 숫자가 있을 때까지 카운트하여 있으면 f..