카타 8급 Return Negative

1 C[ | ]

int makeNegative(int num) {
  if(num>0) return -num;
  return num;
}
int makeNegative(int num) {
  return -abs(num);
}

2 C++[ | ]

3 Kotlin[ | ]

class Kata {
    fun makeNegative(x: Int): Int {
        if (x>0) return -x else return x
    }
}
class Kata {
    fun makeNegative(x: Int) = if(x <= 0) x else -x
}
import kotlin.math.abs
class Kata {
    fun makeNegative(x: Int) = -abs(x)
}
import kotlin.math.absoluteValue
class Kata {
    fun makeNegative(x: Int) = -x.absoluteValue    
}
문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}