Skip to content

Conversation

@lectura7942
Copy link
Collaborator

@lectura7942 lectura7942 commented Apr 13, 2023

📌 푼 문제들

  • [못생긴 수]
  • [편집 거리]

📝 간단한 풀이 과정

[못생긴 수]

  • dp[i]: i 번째 못생긴 수
    • j < i인 모든 j에 대해 dp[j]*2, dp[j]*3, dp[j]*5를 본다.
    • dp[i-1]보다 큰 값 중 최소값을 골라 dp[i]에 넣는다.

[편집 거리]

(추가)
leetcode로 돌려보니 틀린 풀이네요. 😭

  • A,B는 인덱스 0부터 시작.
  • dp[a][b] : A의 a번째 문자, B의 b번째 문자까지 비교했을 때 일치하는 가장 긴 부분문자열 길이
    • 패딩이 있어서 인덱스 1 부터 시작.
  • same[b] = a : B의 b번째 문자와 A의 a번째 문자가 일치
    • -1 이면 A 문자와 일치하지 않음
  • same을 활용해서 서로 일치하지 않는 문자 개수를 구하면 답.

예시1

A_len = 5, B_len = 6
same = [-1, 2, -1, 3, -1, -1]
(1) A와 일치하지 않은 B문제 교체/삭제/삽입: -1의 개수
(2) B와 일치하지 않은 A문자 중 뒷부분 삭제: A_len - 3 -1 = 1 개
(3) B와 일치하지 않은 A문자 중 앞부분 삭제: 2 개

예시2

A = sunday
B = saturday
ans = 3
same = [0, -1, -1, 1, -1, 3, 4, 5]
dp   s  a  t  u  r  d  a  y
 s  [1, 1, 1, 1, 1, 1, 1, 1]
 u  [1, 1, 1, 2, 2, 2, 2, 2]
 n  [1, 1, 1, 2, 2, 2, 2, 2]
 d  [1, 1, 1, 2, 2, 3, 3, 3]
 a  [1, 2, 2, 2, 2, 3, 4, 4]
 y  [1, 2, 2, 2, 2, 3, 4, 5]

Copy link
Collaborator

@Da-Hye-JUNG Da-Hye-JUNG left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[못생긴 수]
prim각각 곱해주는 for문을 제외하고 2중 for문으로 교차로 곱해주면서 list에 넣어주셨네요. 잘 보았습니다.

[편집 거리]
A문자와 B문자의 일치를 나타내는 same으로 푸신 아이디어 좋은 것 같아요!
제 생각에는 same[b] = a (B의 b번째 문자와 A의 a번째 문자가 일치) 에서 b번째 문자와 일치하는 a번째 문자가 여러개 일때 케이스를 고려해야할 것 같아요! 고생많으셨습니다 ㅎㅎ

Copy link
Member

@JLake310 JLake310 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[못 생긴 수]
어떤 수를 봐야할 지 범위 비교를 통해 정한 풀이 잘 봤습니다!

[편집 거리]
저와 비슷하게 lcs를 어느 정도 활용한 풀이 같습니다,,! 잘 봤습니다.

고생하셨어요 👍🏻

Copy link
Collaborator

@hoooolllly hoooolllly left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[못생긴 수]
조건문을 넣어줘서 빠르게 계산되는 것 같습니다!

[편집거리]
생각하신 아이디어를 구현하신 것 대단합니다! 고생하셨습니다!

Copy link
Member

@yunjinchoidev yunjinchoidev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[못생긴 수]
이렇게 구해야 dp로 순서를 보장할 수가 있군요. 잘 봤습니다.

[편집거리]
일치하는 가장 긴 부분 문자열 구하는 부분 잘 봤습니다! 고생 많으셨어요!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants