문제
이 문제는 성별이 m일 때는, f로 f일때는 m으로 바꿔줘야하는 문제이다.
if문을 사용할 수도 있는데, if문으로 했을 때는 289ms, switch문으로 했을 때는, 156ms 를 거쳤다.
update salary(테이블)
set
sex =
CASE
when sex= 'm'
then 'f'
when sex = 'f'
then 'm'
END
when 조건문을 충족하면, then 값을 리턴한다.
* END 안적어주면 문법 오류 생긴다
문제 출처 : https://leetcode.com/problems/swap-salary/
Swap Salary - LeetCode
Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview.
leetcode.com
627번 swap-salary
반응형
댓글