본문 바로가기

IT/알고리즘87

89] 프로그래머스 x 사이의 개수 Kotlin class Solution { fun solution(myString: String): IntArray { var answer = mutableListOf() var splitStr = myString.split('x') for (str in splitStr) { answer.add(str.length) } return answer.toIntArray() } } class Solution { fun solution(myString: String): IntArray { var answer: IntArray = intArrayOf() var list = myString.split("x") for (i in list) { answer += i.length } return answer } } class Solu.. 2023. 12. 15.
88] Kotlin 프로그래머스 문자열 바꿔서 찾기 https://school.programmers.co.kr/learn/courses/30/lessons/181864 프로그래머스코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.programmers.co.kr class Solution { fun solution(myString: String, pat: String): Int { val chagedString = myString.replace('A' , 'X').replace('B', 'A').replace('X', 'B') if(chagedString.contains(pat)) return 1 else return 0 } } 2023. 12. 11.
88] 프로그래머스 숨어있는 숫자의 덧셈 (1) Kotlin char는 toInt 했을때 int가 반환되지 않는다. char.toString().toInt() 해줘야한다. class Solution { fun solution(my_string: String): Int { var answer: Int = 0 for(i in 0 until my_string.length){ if(my_string[i] in '1' .. '9') { answer += my_string[i].toString().toInt() } } return answer } } https://kotlinworld.com/436 [Kotlin] Char을 Int로 변환하는 세가지 방법 알아보기 : Char to IntChar을 Int로 변환할 때 많은 실수가 생기는 이유 Kotlin은 하나의 자료형을 다.. 2023. 10. 23.
87] 프로그래머스 짝수는 싫어요 kotlin class Solution { fun solution(n: Int): IntArray { val mulist = mutableListOf() for(i in 0 .. n) { if(i%2 == 1) mulist.add(i) } return mulist.toIntArray() } } https://hwan-shell.tistory.com/247 Kotlin] MutableList 기능 설명1. MutableListKotlin의 List에는 List와 MutableList가 있습니다.List는 읽기 전용이며 MutableList는 읽기/ 쓰기가 가능합니다. Kotlin에선 List인 listOf의 사용을 권장하고 있습니다. (코드의 선명함과 안정성 때hwan-shell.tistory.com 2023. 10. 15.