# Leetcode 解題速記 14. longest common prefix
###### tags: `LeetCode` `C++`
題敘:
---
Write a function to find the longest common prefix string amongst an array of strings.
If there is no common prefix, return an empty string "".
測資範圍:
---
* 1 <= strs.length <= 200
* 0 <= strs[i].length <= 200
* strs[i] consists of only lower-case English letters.
解題筆記:
---
以第一個字串為對照組,逐一比對後面字串即可
程式碼:
---
```c=
char * longestCommonPrefix(char ** strs, int strsSize){
char* temp;
int i,j;
if(strsSize<=0){
return "";
}
temp=strs[0];
for(i=1;i<strsSize;i++){
j=0;
while(temp[j]&&strs[i][j]&&temp[j]==strs[i][j]){
j++;
}
temp[j]='\0';
}
return temp;
}
```