Skip to content

Commit

Permalink
first solution (#83)
Browse files Browse the repository at this point in the history
* first solution

* update
  • Loading branch information
ayshachakure authored Oct 1, 2023
1 parent 77b5acd commit 36bcd02
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions LeetCode/Algorithms/Easy/LongestCommonPrefix.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
class Solution {
public:
string longestCommonPrefix(vector<string>& strs) {
if (strs.empty())
return "";

for (int i = 0; i < strs[0].length(); ++i)
for (int j = 1; j < strs.size(); ++j)
if (i == strs[j].length() || strs[j][i] != strs[0][i])
return strs[0].substr(0, i);

return strs[0];
}
};

0 comments on commit 36bcd02

Please sign in to comment.