LeetCode 1323 6和9组成的最大数字(java)

it2023-02-13  93

class Solution { public int maximum69Number (int num) { int pos = 0, temp = num, n =1; while(temp != 0) { pos = temp % 10 == 6 ? n : pos; temp = temp / 10; n ++; } return pos == 0 ? num : num + 3 * (int) Math.pow(10, pos - 1); } }
最新回复(0)