Java

    제네릭에 대한 간단한 정리

    모든 소스 코드는 https://github.com/lkimilhol/tistoryblog에서 확인 가능합니다! 안녕하세요. 이번에는 제네릭을 살펴볼까 합니다. 많은 분들이 generic에 이해하고 계실텐데요. 간단한 예제 정도로 정리만 해보려고 해요. (사실 코딩할때 제네릭을 잘 써본적이 없었거든요) 1. 제네릭을 사용하는 이유? 제네릭을 사용하는 이유는 무엇일까요? 저는 제네릭을 사용하는 이유에 대해서 타입 체크가 컴파일 타임에 이루어 진다. 리턴 타입을 제한 할 수 있다. 로 이해하였습니다. 예시를 들어보겠습니다. 1. 타입 체크가 컴파일 타임에 이루어 진다. UseClass.java public class UseClass { public void exceptionExample() { List te..

    [LeetCode] Single Number

    https://leetcode.com/problems/single-number/ Given a non-empty array of integers nums, every element appears twice except for one. Find that single one. You must implement a solution with a linear runtime complexity and use only constant extra space. Example 1: Input: nums = [2,2,1] Output: 1 Example 2: Input: nums = [4,1,2,1,2] Output: 4 Example 3: Input: nums = [1] Output: 1 Constraints: 1

    3주차 미션 - Lazy 로딩과 equals 메서드

    모든 소스 코드는 https://github.com/lkimilhol/atdd-subway-admin/에서 확인 가능합니다! 안녕하세요. 이번에는 lazy 로딩과 관련한 문제 하나를 설명해볼까 해요. lazy 로딩은 JPA에서 활용되는 데이터를 불러오는 방식 중 하나로 실제로 데이터를 사용하기 전에는 proxy 객체를 활용해 실제로 select가 이루어지지 않고 실제 데이터를 사용할때 select를 해오는 기술이라고 생각 할 수 있습니다. 이렇게 된다면 실제로 사용하지 않는 데이터의 조회를 하지 않기 때문에 성능상의 이점이 있을 수 있다고 생각할 수 있습니다. 하지만 lazy 로딩을 사용하다 보면 예기치 못한 일들이 참 많이 발생하곤 하는데요. 저는 그 중 하나인 lazy 로딩과 equals 메서드에 관..

    [Codility] Stacks and Queues. Brackets

    https://app.codility.com/programmers/lessons/7-stacks_and_queues/brackets/ A string S consisting of N characters is considered to be properly nested if any of the following conditions is true: S is empty;S has the form "(U)" or "[U]" or "{U}" where U is a properly nested string;S has the form "VW" where V and W are properly nested strings. For example, the string "{[()()]}" is properly nested bu..

    [Codility] Algorithmic skills. FirstUnique

    https://app.codility.com/programmers/trainings/4/first_unique/ A non-empty array A consisting of N integers is given. The unique number is the number that occurs exactly once in array A. For example, the following array A: A[0] = 4 A[1] = 10 A[2] = 5 A[3] = 4 A[4] = 2 A[5] = 10 contains two unique numbers (5 and 2). You should find the first unique number in A. In other words, find the unique nu..

    [프로그래머스] 완전탐색. 수포자

    https://programmers.co.kr/learn/courses/30/lessons/42840 문제 설명 수포자는 수학을 포기한 사람의 준말입니다. 수포자 삼인방은 모의고사에 수학 문제를 전부 찍으려 합니다. 수포자는 1번 문제부터 마지막 문제까지 다음과 같이 찍습니다. 1번 수포자가 찍는 방식: 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, ... 2번 수포자가 찍는 방식: 2, 1, 2, 3, 2, 4, 2, 5, 2, 1, 2, 3, 2, 4, 2, 5, ... 3번 수포자가 찍는 방식: 3, 3, 1, 1, 2, 2, 4, 4, 5, 5, 3, 3, 1, 1, 2, 2, 4, 4, 5, 5, ... 1번 문제부터 마지막 문제까지의 정답이 순서대로 들은 배열 answers가 주어졌을 ..

    [Hackerrank] Strings. Java String Reverse

    https://www.hackerrank.com/challenges/java-string-reverse/problem A palindrome is a word, phrase, number, or other sequence of characters which reads the same backward or forward. Given a string A, print Yes if it is a palindrome, print No otherwise. Constraints A will consist at most 50 lower case english letters. Sample Input madam Sample Output Yes 쉬운 문제입니다. 문자열이 palindrome(거꾸로 읽어도 동일한 문자열)일 ..

    MongoDB를 활용하여 Repository 구현

    모든 소스 코드는 https://github.com/lkimilhol/matchingProject 에서 확인 가능합니다. 안녕하세요. 저번에 MongoDB(이하 몽고) 설치하였고, 계속해서 간단하게 데이터가 들어가는지 정도 확인을 했었는데요. 이번에는 기획 단계를 하나 추가해 볼까 해요. 바로 주문 히스토리를 몽고를 사용하여 쌓도록 하는 것입니다. 다음과 같은 생각으로 이런 기획을 결정하였어요. NOSQL에서 업데이트가 빈번하지 말아야 한다. 히스토리 기록은 계속해서 데이터를 쌓는다. 히스토리 기록을 통해 데이터를 조회하고 이를 가공해서 추후에 지표를 추출 할 수 있다. 이 때 몽고디비가 적절할 것이라고 판단했다. 몽고는 확장에 용이하기에 서비스의 트래픽이 증가하면 이에 대한 관리가 쉬울 것. 위의 내용..

    간단하게 상속과 조합을 이해해보기

    안녕하세요. 이번에는 상속과 조합에 대해서 고민을 해보려고합니다. 상속은 인터페이스의 상속, 확장을 뜻하는 것이 아닌 클래스를 상속 받아 확장하는 것으로 제한 하겠습니다. 모든 소스 코드는 https://github.com/lkimilhol/tistoryblog 에서 확인 할 수 있습니다. 예제를 보도록 하겠습니다. 우리는 카드를 통해 게임을 구현하려 합니다. 이 게임은 카드 뭉치 속에 내가 택한 번호가 있는지를 가려냅니다. 1. 어떤 문제가 있을까? Cards.java class Cards { protected List numbers = new ArrayList(); protected Cards() {} protected Cards(List numbers) { this.numbers = numbers;..

    [LeetCode] 1528. Shuffle String

    Given a string s and an integer array indices of the same length. The string s will be shuffled such that the character at the ith position moves to indices[i] in the shuffled string. Return the shuffled string. Example 1: Input: s = "codeleet", indices = [4,5,6,7,0,2,1,3] Output: "leetcode" Explanation: As shown, "codeleet" becomes "leetcode" after shuffling. Example 2: Input: s = "abc", indice..