https://school.programmers.co.kr/learn/courses/30/lessons/120841
class Solution {
fun solution(dot: IntArray): Int {
var answer: Int = 0
if(dot[0] > 0 && dot[1] > 0){
answer = 1
}else if (dot[0] < 0 && dot[1] > 0){
answer = 2
}else if (dot[0] < 0 && dot[1] < 0 ){
answer = 3
}else if (dot[0] > 0 && dot[1] < 0){
answer = 4
}
return answer
}
}
//다른 사람의 풀이
class Solution {
fun solution(dot: IntArray) = when {
(dot[0] > 0 && dot[1] > 0) -> 1
(dot[0] < 0 && dot[1] > 0) -> 2
(dot[0] < 0 && dot[1] < 0) -> 3
else -> 4
}
}
https://school.programmers.co.kr/learn/courses/30/lessons/120850
class Solution {
fun solution(my_string: String): IntArray {
var answer: IntArray = intArrayOf()
for(i in my_string){
var a = i.digitToIntOrNull()
if(a!=null){
answer = answer.plus(a)
}
}
answer.sort()
return answer
}
}
//다른 사람의 풀이
class Solution {
fun solution(my_string: String): IntArray {
return my_string.filter { Character.isDigit(it) }.map { it.digitToInt() }.sorted().toIntArray()
}
}
https://school.programmers.co.kr/learn/courses/30/lessons/120893
class Solution {
fun solution(my_string: String): String {
var answer: String = ""
for(i in my_string){
var a = ""
if(i.isLowerCase()){
a = i.uppercase()
}else{
a = i.lowercase()
}
answer += a
}
return answer
}
}
// 다른 사람의 풀이
class Solution {
fun solution(my_string: String): String =
my_string.map { Char((it.code - 33) % 64 + 65) }.joinToString("")
}
https://school.programmers.co.kr/learn/courses/30/lessons/120895
class Solution {
fun solution(my_string: String, num1: Int, num2: Int): String {
var answer: String = ""
for(i in 0 until my_string.length){
var a = ""
if(i==num1){
a += my_string[num2]
}else if(i==num2){
a += my_string[num1]
}else{
a += my_string[i]
}
answer += a
}
return answer
}
}
//다른 사람의 풀이
class Solution {
fun solution(my_string: String, num1: Int, num2: Int): String {
var stringArray = my_string.toCharArray()
val tempValue = stringArray[num1]
stringArray[num1] = stringArray[num2]
stringArray[num2] = tempValue
return stringArray.joinToString("")
}
}