diff --git a/2022-Oct/18 Oct 2022/Longest Common Prefix b/2022-Oct/18 Oct 2022/Longest Common Prefix new file mode 100644 index 0000000..92741ba --- /dev/null +++ b/2022-Oct/18 Oct 2022/Longest Common Prefix @@ -0,0 +1,18 @@ +class Solution { +public: + string longestCommonPrefix(vector& a) { + + + string ans = ""; + for (int i = 0; i < a[0].size(); i++) { + char cur = a[0][i]; + for (string s : a) { + if (s.size() == i or s[i] != cur) return ans; + } + ans += cur; + } + return ans; + + + } +};