daily pastebin goal
91%
SHARE
TWEET

Untitled

a guest Apr 22nd, 2018 56 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. class Solution {
  4.     public:
  5.         string longestCommonPrefix(vector<string>& strs) {
  6.             string ans = "";
  7.             for(int i = 0 ; i < (int)strs[0].length() ; i++){
  8.                 for(int j = 1 ; j < (int)strs.size() ; j++){
  9.                     if(i >= (int)strs[j].length() || strs[j][i] != strs[0][i]) return ans;
  10.                 }
  11.                 ans += strs[0][i];
  12.             }
  13.             return ans;
  14.         }
  15. };
  16. int main(){
  17.     return 0;
  18. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top