LeetCode Weekly Contest 273 2問目 - Execution of All Suffix Instructions Staying in a Grid [2120]

Source

LeetCode Weekly Contest 273
問題文

問題概要

省略

解法

省略

cLay(version 20211231-1)のコード

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

#define main dummy_main
{}
#undef main

class Solution {
public:
  VI executeInstructions(int n, VI& startPos, string s) {
    VI res;
    int tmp, x, y;
    rep(m,s.size()){
      tmp = 0;
      (x, y) = (startPos[0], startPos[1]);
      rep(i,m,s.size()){
        if(s[i]=='U') x--;
        if(s[i]=='D') x++;
        if(s[i]=='L') y--;
        if(s[i]=='R') y++;
        if(x < 0 || y < 0 || x >= n || y >= n) break;
        tmp++;
      }
      res.push_back(tmp);
    }
    return res;
  }
};

Current time: 2024年05月18日23時44分45秒
Last modified: 2022年01月02日03時40分30秒 (by laycrs)
Tags: Competitive_Programming_Incomplete LeetCode
トップページに戻る

Logged in as: unknown user (not login)

ログイン: