본문 바로가기
python-algorithm

leetcode 2937. Make Three Strings Equal

by 무적김두칠 2024. 2. 8.

https://leetcode.com/problems/make-three-strings-equal/description/

 

LeetCode - The World's Leading Online Programming Learning Platform

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

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
class Solution:
    def findMinimumOperations(self, s1: str, s2: str, s3: str-> int:
        common_prefix = ''
        for i in range(min(len(s1), len(s2), len(s3))):
            if s1[i] == s2[i] and s2[i] == s3[i]:
                common_prefix += s1[i]
            else:
                break
        cnt = len(s1) + len(s2) + len(s3) - len(common_prefix) * 3
        if common_prefix == '' :
            return -1
        else:
            return cnt
        
cs
반응형

'python-algorithm' 카테고리의 다른 글

백준 14215 세 막대  (0) 2024.02.08
백준 1308 D-Day  (1) 2024.02.08
백준 25206 너의 평점은  (0) 2024.02.06
leetcode 3028. Ant on the Boundary  (0) 2024.02.06
leetcode 3019. Number of Changing Keys  (0) 2024.02.05

댓글