https://leetcode.com/problems/maximum-69-number/
| 4 | * https://leetcode.com/problems/maximum-69-number/ |
| 5 | */ |
| 6 | public class Sanghoo { |
| 7 | |
| 8 | /** |
| 9 | * 문제 내 1 <= num <= 10^4 인 점을 활용 |
| 10 | * 제일 큰 자리수로 6이 나오면 그 수를 바꿔주면 끝 |
| 11 | * 99699 > 99699 + 300 = 99999 |
| 12 | */ |
| 13 | public int maximum69Number (int num) { |
| 14 | int res = num; |
| 15 | |
| 16 | int x = 1000; |
| 17 | while(num > 0) { |
| 18 | if(num/x == 6) { |
| 19 | res += x*3; |
| 20 | break; |
| 21 | } |
| 22 | num = num%x; |
| 23 | x /= 10; |
| 24 | } |
| 25 | |
| 26 | return res; |
| 27 | } |
| 28 | |
| 29 | } |
nothing calls this directly
no outgoing calls
no test coverage detected