LeetCode Biweekly Contest 10 1問目 - Intersection of Three Sorted Arrays [1213]

Source

LeetCode Biweekly Contest 10
問題文

問題概要

省略

解法

省略

cLayversion 20191006-1)のコード

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

#define main dummy_main
{}
#undef main

class Solution {
public:
  vector<int> arraysIntersection(vector<int>& A, vector<int>& B, vector<int>& C) {
    int a = 0, b = 0, c = 0, m;
    vector<int> res;
    while(a < A.size() && b < B.size() && c < C.size()){
      if(A[a] == B[b] == C[c]){
        res.push_back(A[a]);
        a++; b++; c++;
      } else {
        m = min(A[a], B[b], C[c]);
        if(m==A[a]) a++;
        if(m==B[b]) b++;
        if(m==C[c]) c++;
      }
    }
    return res;
  }
};

Current time: 2024年04月16日18時43分17秒
Last modified: 2019年10月06日03時50分16秒 (by laycrs)
Tags: Competitive_Programming_Incomplete LeetCode
トップページに戻る

Logged in as: unknown user (not login)

ログイン: