일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | |||
5 | 6 | 7 | 8 | 9 | 10 | 11 |
12 | 13 | 14 | 15 | 16 | 17 | 18 |
19 | 20 | 21 | 22 | 23 | 24 | 25 |
26 | 27 | 28 | 29 | 30 | 31 |
Tags
- var
- VUE
- leetcode
- condition
- docker
- bash
- nginx
- type
- AI
- JavaScript
- webpack
- TypeScript
- 보안
- Python
- generic
- C++
- vue.js
- loop
- git
- machine learning
- scss
- C#
- dotenv
- npm
- BOJ
- property
- vuetify
- security
- Clone
- 앙상블
Archives
- Today
- Total
ice rabbit programming
[LeetCode] Longest Common Prefix 본문
https://leetcode.com/problems/longest-common-prefix/
[
Longest Common Prefix - LeetCode
Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview.
leetcode.com
](https://leetcode.com/problems/longest-common-prefix/)
겹치는 가장 긴 prefix를 구하는 문제이다. 단순하게 풀었다. 이 문제도 C#
// C#
public class Solution {
public string LongestCommonPrefix(string[] strs) {
if(strs.Length<1)
return "";
string result="";
string source=strs[0];
for(int i=0;i<source.Length;i++) {
char cmpChar = source[i];
for(int j=1;j<strs.Length;j++) {
if(i>=strs[j].Length)
return result;
if(strs[j][i]!=cmpChar)
return result;
}
result+=cmpChar;
}
return result;
}
}
'PS > LeetCode' 카테고리의 다른 글
[LeetCode] Maximum Subarray (0) | 2020.04.15 |
---|---|
[LeetCode] Valid Parenthese (0) | 2020.04.15 |
[LeetCode] Remove Element (0) | 2020.04.15 |
[LeetCode] Remove Duplicates From Sorted Array (0) | 2020.04.15 |
[LeetCode] 9. Palindrome Number (0) | 2020.04.12 |