Java

Programming/Algorithm

[Java-알고리즘] Split a String in Balanced Strings

[Problem] Balanced strings are those who have equal quantity of 'L' and 'R' characters. Given a balanced string s split it in the maximum amount of balanced strings. Return the maximum amount of splitted balanced strings. [Example1] Input: s = "RLRRLLRLRL" Output: 4 Explanation: s can be split into "RL", "RRLL", "RL", "RL", each substring contains same number of 'L' and 'R'. [Example2] Input: s ..

Programming/Algorithm

[Java-알고리즘] Jewels and Stones

[Problem] You're given strings J representing the types of stones that are jewels, and S representing the stones you have. Each character in S is a type of stone you have. You want to know how many of the stones you have are also jewels. The letters in J are guaranteed distinct, and all characters in J and S are letters. Letters are case sensitive, so "a" is considered a different type of stone ..

Programming/Algorithm

[Java-알고리즘] IP 주소 분리

요즘 https://leetcode.com 에서 알고리즘 문제를 풀고 있다. 수행속도 및 메모리 사용량까지 모두 측정해줘서 좋았고, 문제를 푼 사람들 중에 내가 푼 방법의 효율성을 알려주는 부분도 좋았다. 앞으로는 계속 leet code 문제를 올릴 것 같다. [Problem] Given a valid (IPv4) IP address, return a defanged version of that IP address. A defanged IP address replaces every period "." with "[.]". [Example1] Input: address = "1.1.1.1" Output: "1[.]1[.]1[.]1" [Example2] Input: address = "255.100.50.0..

Programming/Spring

[Spring Boot] Spring Security with REST API Login AS JSON

최근 기존에 NodeJS와 Typescript, NestJS으로 이루어진 API 서버를 Java와 Spring Boot 환경으로 마이그레이션 작업을 진행하고 있다. 그중 Spring Security를 적용하면서 REST API 형태로 JSON으로 Login 요청을 날리면 Spring Security에서는 데이터를 받지 못하고 해당 요청을 Block 하는 이슈가 있어서 이를 확인하고 해결한 과정을 기록해본다. Spring Security는 여러개의 Filter들이 묶여서 동작하는 Filter Chain으로 이루어져 있다. 그렇다면 Login을 담당하는 Filter는 어떤 것일까? SecurityConfiguration 클래스를 작성하다 보면 다음과 같은 메소드를 볼 수 있을 것이다. package com...

Programming/Scala

[Scala-03] 클래스에 대하여

Scala는 객체지향의 개념과 함수형의 개념이 섞인 언어이다. 객체지향 개념이 있듯이 Scala에는 당연히 Class가 존재한다. Scala에서의 Class는 Java의 Class와 유사하지만, Scala에서는 Class가 파라미터를 가질 수 있다는 차이점을 갖고 있다. 아래 소스코드는 Scala 코드로 작성한 파라미터를 가지는 Class의 예제이다. class Complex(real: Double, imaginary: Double) { def re() = real def im() = imaginary } 이 Complex Class (복소수 클래스)는 두 개의 인자를 받는다. 하나는 복소수의 실수 부분이고, 또 다른 하나는 복소수의 허수 부분에 해당한다. 이 파라미터는 Complex 클래스의 인스턴스를..

Programming/Scala

[Scala-02] Scala에서 Java Class 사용하기

Scala의 장점 중 하나는 Java 코드를 사용할 수 있다는 점이다. 사용하고 싶은 Java 클래스를 import 하여 사용하면 된다. 또한 java.lang 패키지 하위에 있는 모든 클래스들은 Scala에선 따로 import 하지 않아도 기본적으로 사용할 수 있다. 다음은 Java 코드를 Scala 코드에 적용해보겠다. Java의 Date class와 Dateformat class는 날짜 관련한 유틸리티 클래스로 강력한 기능을 제공하고 있다. 이를 Scala 코드에서 다음과 같이 사용할 수 있다. [ 현재 시간을 한국에서 사용하는 시간대 표현으로 출력하는 코드 ] import java.text.DateFormat._ import java.util.{Date, Locale} object KoreaDat..

Programming/Algorithm

[Java - 알고리즘] 직사각형의 좌표 구하기

문제: 직사각형의 좌표 구하기 설명: 직사각형을 만드는데 필요한 4개의 점 중 3개가 주어질 때, 나머지 한 점의 좌표를 구하려고 합니다. 점 3개의 좌표가 들어있는 배열 coordinates 가 매개변수로 주어질 때, 직사각형을 만드는데 필요한 나머지 한 점의 좌표를 return 하도록 함수를 작성해주세요. 단, 직사각형의 각 변은 x 축, y축에 평행하며, 반드시 직사각형을만들 수 있는 경우만 입력으로 주어집니다. 입력 및 출력 예: 입력 출력 [[1,4],[3,4],[3,10]] [1,10] [[1,1],[2,2],[1,2]] [2,1] 위 문제는 다음과 같이 간단하게 xor 연산으로 풀어낼 수 있다. package com.tistory.johnmarc; import java.util.Arrays;..

Programming/Scala

[Scala-01] Hello World 출력하기

스칼라 프로젝트를 만들고, Hello World를 출력해보는 코드를 작성해보자. 일반적으로 자바 프로그래밍을 해본 사람이라면 Hello World 코드를 다음과 같이 작성할 것이다. public class HelloWorld { public static void main(String[] args) { System.out.println("Hello, World"); } } 반면 스칼라 코드는 다음과 같다. object Helloworld { def main(args: Array[String]): Unit = { println("Hello, World") } } 자바에서 정적멤버(함수 또는 필드)를 선언하기 위해 클래스의 일부로 정적 멤버를 정의한다. 하지만 정적멤버에 대한 개념이 없는 스칼라에서는 이러한 ..

JohnMark
'Java' 태그의 글 목록 (3 Page)