MCPcopy Create free account
hub / github.com/ROUTINE-STUDY/Algorithm / Sanghoo

Class Sanghoo

LeetCode/Greedy/1323. Maximum 69 Number/Sanghoo.java:6–29  ·  view source on GitHub ↗

https://leetcode.com/problems/maximum-69-number/

Source from the content-addressed store, hash-verified

4 * https://leetcode.com/problems/maximum-69-number/
5 */
6public 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}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected