LeetCode Biweekly Contest 8 2問目 - Before and After Puzzle [1181]

Source

LeetCode Biweekly Contest 8
問題文

問題概要

省略

解法

省略

cLayversion 20190914-1)のコード

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

#define main dummy_main
{}
#undef main

class Solution {
public:
  vector<string> beforeAndAfterPuzzles(vector<string>& in) {
    int i, j, k, N;
    vector<string> a, b;
    set<string> s;
    set<string>::iterator it;
    vector<string> res;

    N = in.size();
    rep(i,N) rep(j,N) if(i!=j){
      a = Explode(in[i], " ");
      b = Explode(in[j], " ");
      if(a[a.size()-1] == b[0]){
        rep(k,1,b.size()) a.push_back(b[k]);
        s.insert( Implode(a, " ") );
      }
    }

    for(it=s.begin(); it!=s.end(); it++) res.push_back(*it);
    return res;
  }
};

Current time: 2024年04月20日00時55分44秒
Last modified: 2019年09月14日17時09分41秒 (by laycrs)
Tags: Competitive_Programming_Incomplete LeetCode
トップページに戻る

Logged in as: unknown user (not login)

ログイン: