LeetCode Weekly Contest 243 2問目 - Maximum Value after Insertion [1881]

Source

LeetCode Weekly Contest 243
問題文

問題概要

省略

解法

省略

cLayversion 20210607-1)のコード

C++に変換後のコードはこちら

#define main dummy_main
{}
#undef main

class Solution {
public:
  string maxValue(string n, int x) {
    int N = n.size();
    if(n[0] == '-'){
      rep(i,1,N) if(n[i] - '0' > x) break;
      n = n.substr(0,i) + (char)(x+'0') + n.substr(i);
    } else {
      rep(i,N) if(n[i] - '0' < x) break;
      n = n.substr(0,i) + (char)(x+'0') + n.substr(i);
    }
    return n;
  }
};

Current time: 2024年04月26日00時13分45秒
Last modified: 2021年06月07日19時37分27秒 (by laycrs)
Tags: Competitive_Programming_Incomplete LeetCode
トップページに戻る

Logged in as: unknown user (not login)

ログイン: