Skip to content

Conversation

yolophg
Copy link
Contributor

@yolophg yolophg commented Jul 3, 2024

  • Graph Valid Tree
  • Number of Connected Components in an Undirected Graph
  • House Robber
  • House Robber II
  • Longest Palindromic Substring

@yolophg yolophg marked this pull request as draft July 3, 2024 17:50
// expand around the current character
expandAroundCenter(i, i);
// expand around the current and next character
expandAroundCenter(i, i + 1);
Copy link
Contributor

@dev-jonghoonpark dev-jonghoonpark Jul 5, 2024

Choose a reason for hiding this comment

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

같은 함수를 여기서 right를 1 더해서 한 번 더 호출하는 이유는 뭘까요?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

두 번째 호출에서 right를 1 더해서 호출하는 이유는 문자열 내의 두 가지 경우의 대칭 문자열을 모두 처리하기 위한 구현이에요!

expandAroundCenter(i, i) 호출은 홀수 길이의 대칭 문자열을 찾기 위한 것이고, expandAroundCenter(i, i + 1) 호출은 짝수 길이의 대칭 문자열을 위한 것입니다.

Copy link
Contributor

Choose a reason for hiding this comment

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

오 길이별로 나눠서 진행을 하신거군요 ㅎㅎ
재밌는 접근인것 같습니다 : )

Copy link
Contributor

Choose a reason for hiding this comment

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

var longestPalindrome = function (s) {
  let maxPalindrome = '';

  // to expand around the center and update the start and maxLength
  function expandAroundCenter(center) {
    let left = center;
    let right = center;

    while (right < s.length - 1 && s[center] === s[right + 1]) {
      right++;
    }

    while (left > 0 && right < s.length - 1 && s[left - 1] === s[right + 1]) {
      left--;
      right++;
    }

    if (maxPalindrome.length < right - left + 1) {
      maxPalindrome = s.substring(left, right + 1);
    }
  }

  // iterate through each character in the string
  for (let i = 0; i < s.length; i++) {
    // expand around the current character
    expandAroundCenter(i);
  }

  // return the longest palindromic substring
  return maxPalindrome;
};

이렇게도 작성 가능하네요

@yolophg yolophg requested a review from bky373 July 6, 2024 07:34
@yolophg yolophg marked this pull request as ready for review July 6, 2024 07:34
Copy link
Contributor

@bky373 bky373 left a comment

Choose a reason for hiding this comment

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

깔끔하게 코드 작성해주시고, 주석이 친절하게 추가되어 있어서 읽기 좋았습니다~ 고생하셨습니다!

Comment on lines +21 to +23
if (root1 !== root2) {
parent[root1] = root2;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

루트가 둘 중 하나이면 되니 여기에서는 크기 비교를 따로 하지 않아도 되는군요! union find 풀이법 흥미롭게 잘 보았습니다!

@yolophg yolophg merged commit dcdf35f into DaleStudy:main Jul 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
No open projects
Status: Done
Development

Successfully merging this pull request may close these issues.

3 participants