-
[BOJ 2455] 백준 알고리즘 2455Algo 2019. 3. 3. 18:42
백준 알고리즘 2455번을 코틀린으로 풀었습니다.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersimport java.util.* import kotlin.collections.ArrayList fun main(args : Array<String>){ var check = 0 val read = Scanner(System.`in`) var people : ArrayList<Int> = arrayListOf(0) do{ val minus = read.nextInt() * (-1) val plus = read.nextInt() people.add((people.last())+minus+plus) if(minus * plus == 0){ check++ } }while(check<2) println(people.max()) } #Comment
저는 문제를 잘못 해석해서 정거장이 4개가 아니라
첫번째 0이 시작역, 두번째 0이 종착역으로
check 라는 변수로 0이 2번 나올 시,
시작역부터 종착역까지 다 완주 하였음으로 while 문을 탈출하게 구현하였습니다.
#Umm
코틀린으로 푼 다른 코드 중 시간복잡도가 적게 걸린 코드를 보면
으로 문제를 접근하여 저보다 시간복잡도가 우수합니다.
해당 관련 포스팅을 하여 자바와 다른 코틀린의 장점을 표현하여 코드를 작성하는 습관을 길러야겠습니다.LIST'Algo' 카테고리의 다른 글
[LeetCode]Reverse Integer (0) 2019.06.22 [LeetCode] Climbing Stairs (0) 2019.05.06 [BOJ-2566]백준 알고리즘 2566 [Kotlin][Java] (0) 2019.04.28 [LeetCode] Two sum (0) 2019.03.10 정해진 범위 안에 배수 구하기. (0) 2018.09.20