[leetcode] Longest Common Prefix --javascript

bang·2020년 12월 27일
0

leetcode

목록 보기
1/1
post-thumbnail

문제설명

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 "".

배열 안에 문자중 가장 긴 접두사를 찾는 함수를 작성하라.
만약 공통 접두사가 없으면 빈 문자를 리턴해라.

예시

Input: strs = ["flower","flow","flight"]
Output: "fl"
Input: strs = ["dog","racecar","car"]
Output: ""
Explanation: There is no common prefix among the input strings.

해결 방법

배열의 첫번 째 문자열에서 첫 문자와 나머지 문자열의 모든 문자를 비교한다.

해결 코드

참고한 블로그

0개의 댓글