<output id="qn6qe"></output>

    1. <output id="qn6qe"><tt id="qn6qe"></tt></output>
    2. <strike id="qn6qe"></strike>

      亚洲 日本 欧洲 欧美 视频,日韩中文字幕有码av,一本一道av中文字幕无码,国产线播放免费人成视频播放,人妻少妇偷人无码视频,日夜啪啪一区二区三区,国产尤物精品自在拍视频首页,久热这里只有精品12

      [LeetCode] 2566. Maximum Difference by Remapping a Digit

      You are given an integer num. You know that Bob will sneakily remap one of the 10 possible digits (0 to 9) to another digit.

      Return the difference between the maximum and minimum values Bob can make by remapping exactly one digit in num.

      Notes:
      When Bob remaps a digit d1 to another digit d2, Bob replaces all occurrences of d1 in num with d2.
      Bob can remap a digit to itself, in which case num does not change.
      Bob can remap different digits for obtaining minimum and maximum values respectively.
      The resulting number after remapping can contain leading zeroes.

      Example 1:
      Input: num = 11891
      Output: 99009
      Explanation:
      To achieve the maximum value, Bob can remap the digit 1 to the digit 9 to yield 99899.
      To achieve the minimum value, Bob can remap the digit 1 to the digit 0, yielding 890.
      The difference between these two numbers is 99009.

      Example 2:
      Input: num = 90
      Output: 99
      Explanation:
      The maximum value that can be returned by the function is 99 (if 0 is replaced by 9) and the minimum value that can be returned by the function is 0 (if 9 is replaced by 0).
      Thus, we return 99.

      Constraints:
      1 <= num <= 108

      替換一個數字后的最大差值。

      給你一個整數 num 。你知道 Danny Mittal 會偷偷將 0 到 9 中的一個數字 替換 成另一個數字。

      請你返回將 num 中 恰好一個 數字進行替換后,得到的最大值和最小值的差為多少。

      注意:

      當 Danny 將一個數字 d1 替換成另一個數字 d2 時,Danny 需要將 nums 中所有 d1 都替換成 d2 。
      Danny 可以將一個數字替換成它自己,也就是說 num 可以不變。
      Danny 可以將數字分別替換成兩個不同的數字分別得到最大值和最小值。
      替換后得到的數字可以包含前導 0 。
      Danny Mittal 獲得周賽 326 前 10 名,讓我們恭喜他。

      思路

      這是一道字符串的實現題。給的 input 是一個字符串,表示一個數字,需要把他變成一個最大的數和一個最小的數,然后求兩者的差值。首先我們思考最大的數是什么?是最高位盡量為 9,如果第一位已經為 9,那么就找到第一個不為 9 的digit,假如為 X,把所有的 X 都替換成 9。

      又因為給的數字一定沒有前導 0,如果最高位出現的數字為 Y,我們把所有的 Y 都替換為 0 即可。

      復雜度

      時間O(n) - 遍歷字符串一次
      空間O(1)

      代碼

      Java實現

      class Solution {
          public int minMaxDifference(int num) {
              String str = String.valueOf(num);
              int max = num;
              for (char c : str.toCharArray()) {
                  if (c != '9') {
                      max = Integer.parseInt(str.replace(c, '9'));
                      break;
                  }
              }
      
              int min = Integer.parseInt(str.replace(str.charAt(0), '0'));
              return max - min;
          }
      }
      
      posted @ 2025-06-14 08:12  CNoodle  閱讀(42)  評論(0)    收藏  舉報
      主站蜘蛛池模板: 久久中文字幕无码专区| 精品久久一线二线三线区| 久久国产精品二国产人妻| 色老板精品无码免费视频| 双鸭山市| 日韩一区二区三区水蜜桃| 久久人与动人物a级毛片 | 给我免费观看片在线| 亚洲a∨无码无在线观看| 国产综合久久久久鬼色| 亚洲国产综合精品2020| 汝南县| 亚洲国产成人综合精品| 亚洲高潮喷水无码AV电影| 免费无码又爽又刺激网站| 亚洲欧美自偷自拍视频图片| 色九九视频| 久热这里只有精品视频六| 中文字幕亚洲人妻一区| 黑人大荫道bbwbbb高潮潮喷| 丰满少妇在线观看网站| 无码AV无码天堂资源网影音先锋| 亚洲综合av一区二区三区| 国产真人无码作爱视频免费| 国产午夜福利一区二区三区| 亚洲日韩一区二区| 亚洲欧美综合精品成人网站| 霍邱县| 日本亲近相奷中文字幕| 精品国产成人一区二区| 亚洲精品揄拍自拍首页一| 国产精品毛片一区二区| 欧美人与性动交ccoo| 亚洲老女人区一区二视频| a∨变态另类天堂无码专区| 久草热大美女黄色片免费看| 50路熟女| 天堂а√在线地址中文在线| 亚洲日韩欧美丝袜另类自拍 | 最新av中文字幕无码专区| 在线观看亚洲精品国产|