PutApiController @RestController @RequestMapping("/api") class PutApiController { @PutMapping("/put-mapping") fun putMapping(): String { return "put-mapping" } @RequestMapping(method = [RequestMethod.PUT], path = ["/request-mapping"]) fun requestMapping(): String { return "request-mapping - put method" } //Post와 동일, Put -> 내용없으면 생성, 있으면 수정 @PutMapping(path = ["/put-mapping/object"]) fun putMappi..
문제 이해 주어진 숫자 중 3개의 수를 더했을때 소수가 된는 경우의 개수 Return 접근 삼중 for문을 사용한 3가지 합의 경우의 수 구하기 플래그 + 합이 소수인지 판별해서 answer++ 풀이 class Solution { fun solution(nums: IntArray): Int { var answer = 0 for (i in 0 until nums.size - 2) { for (j in i + 1 until nums.size - 1) { for (k in j + 1 until nums.size) { var sum = nums[i] + nums[j] + nums[k] var flag = 0 for (l in 2 until sum) { if (sum % l == 0) { flag = 1 brea..
package com.example.mvc.controller.post import com.example.mvc.model.http.UserRequest import org.springframework.web.bind.annotation.* @RestController @RequestMapping("/api") class PostApiController { //현대 방식 @PostMapping("/post-mapping") fun postMapping(): String { return "post-mapping" } //과거 방식 @RequestMapping(method = [RequestMethod.POST], path = ["request-mapping"]) // 주소 외부 노출, url 받는 형식 다..
문제 이해 Input : x, n Return x ~ x 씩 증가 n개 array 접근 리스트 만든후 n개만큼 반복 i (index)를 곱해서 배열에 넣어줌 풀이 class Solution { fun solution(x: Int, n: Int): LongArray { val answer = mutableListOf() for (i in 1..n) { answer.add(x.toLong() * i) } return answer.toLongArray() } } 다른 사람의 풀이 class Solution { fun solution(x: Int, n: Int): LongArray = LongArray(n) { x.toLong() * (it + 1) } }
package com.example.mvc.controller.get import com.example.mvc.model.http.UserRequest import org.springframework.web.bind.annotation.* @RestController //REST API @RequestMapping("/api") //localhost:8080/api class GetApiController { //Get 주소를 노출할때 사용 하는 방법 : 최근 //@GetMapping("/hello") : http://localhost:8080/api/hello @GetMapping(path = ["/hello", "/abcd"]) //Get http://localhost:8080/api/hello, G..
REST 란 ? REST(Representational State Transfer, 자원의 상태 전달) 네트워크 아키텍쳐 원리 RESTful 이란 ? 아래의 몇가지 조건이 잘 지켜진 api가 있을때 RESTful 한 api 라고 할 수 있다. Client, Server : 클라이언트와 서버가 서로 독립적, 분리 Stateless : 요청에 대해서 클라이언트의 상태가 서버에 저장되지 않는다. 요청하는 값을 즉각 요청 ex) 햄버거 가게에서 주문할때, 치즈버거 주문 , 치즈버거 + 콜라 각각 주문, 전에 주문한걸 기억하지 않는다. 캐시 : 클라이언트는 서버의 응답을 캐시 할 수 있다. 클라이언트가 캐시를 통해서 응답을 재사용 할 수 있어야 하며, 이를 통해 서버의 부하를 낮출 수 있다. 계층화(Layered..
문제 이해 행렬의 덧셈 ( 행과 열이 같다 ) 접근 두개의 mapIndexed 함수를 활용하여 각각 더해준다음 반환시킨다 풀이 class Solution { fun solution(arr1: Array, arr2: Array): Array { var answer = arrayOf() answer = arr1.mapIndexed { indexArr, ints -> ints.mapIndexed { indexInts, i -> i + arr2[indexArr][indexInts] }.toIntArray() }.toTypedArray() return answer } }
문제 이해 Return phone_number 뒷자리 제외 " * " 접근 리스트 생성 for문 돌려서 마지막 숫자를 제외한 값에는 * 삽입 풀이 class Solution { fun solution(phone_number: String): String { var answer = arrayListOf() for (i in phone_number.indices) { if (i < phone_number.length - 4) { answer.add("*") } else { answer.add(phone_number[i].toString()) } } return answer.joinToString("") } } 다른 사람의 풀이 fun solution(phone_number: String): String { ..
문제 이해 x % ( x 자릿수의 합 ) == 0 -> 하샤드 Return true/false 접근 map으로 x를 배열화 시켜 요소값의 합을 구해 자리값의 합을 구한다 나눠서 0이 되는 값의 합을 구한다 -> 비교 풀이 class Solution { fun solution(x: Int): Boolean { var answer = true var sum = 0 x.toString().map { sum += (it.toInt() - '0'.toInt()) } return x % sum == 0 } } 다른 사람의 풀이 class Solution { fun solution(x: Int): Boolean { return x % x.toString().fold(0) { acc, c -> acc + c.toInt..
문제 이해 1. 짝수라면 2로 나눔 2. 홀수라면 3을 곱하고 1 더함 3. 같은 작업을 1이될때까지 반복 접근 1이 될때까지 분기 나눠주기 count 500 되는 순간 return 풀이 class Solution { fun solution(num: Int): Int { var longNum = num.toLong() var count = 0 while (count 1) { count ++ longNum = if (longNum % 2 == 0L) longNum / 2 else longNum * 3 + 1 } return if (count == 500) -1 else count } } 다른 사람의 풀이 class Solution { fun solution(num: Int..
문제 이해 두수 n, m 최대 공약수 / 최소공배수 반환 : Array 접근 최대 공약수 함수 작성 유클리드 호제법 나눴을때 나머지가 0이 될때까지 재귀 함수 돌리기 최소 공배수 함수 작성 두수의 곱 / 최대공약수 return 풀이 class Solution { fun solution(n: Int, m: Int): IntArray { return intArrayOf(gcm(n, m), lcm(n, m)) } fun gcm(a: Int, b: Int): Int { var maximum = max(a, b) var minimum = min(a, b) if (minimum == 0) { return maximum } else { return gcm(minimum, maximum % minimum) } } fu..
문제 이해 엄지손가락만으로 터치 왼손 * 시작 오른손 # 시작 상하좌우 이동 2580 의경우에는 현재 왼손, 오른손 위치중 가까운 손으로 터치 접근 숫자의 좌표화(거리 비교) , but 거리는 안구해도됨 Pair의 함수 추가 if 분기 나누고 거리 비교 하기 풀이 import kotlin.math.abs fun main() { val data = intArrayOf(1, 3, 4, 5, 8, 2, 1, 4, 5, 9, 5) val data1 = "right" println(Solution().solution(data, data1)) } class Solution { fun solution(numbers: IntArray, hand: String): String { var answer = "" val ma..