Skip to content

Latest commit

 

History

History

odd-string-difference

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 

Odd string difference

Problem link

Solutions

Solution.cpp

// https://leetcode.com/problems/odd-string-difference/

class Solution {
 public:
  vector<int> conv(const string& s) {
    vector<int> ret;
    for (int i = 0, n = s.size(); i < n - 1; ++i)
      ret.push_back(s[i + 1] - s[i]);
    return ret;
  }
  string oddString(vector<string>& words) {
    map<vector<int>, vector<string>> m;
    for (auto& w : words) m[conv(w)].push_back(w);
    for (auto& [k, v] : m)
      if (v.size() == 1) return v[0];
    return "";
  }
};

Tags