Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[2024-02-23] 최승현 자스로 푼 배열문제 #110

Merged

Conversation

ChoiWheatley
Copy link
Contributor

leet 1657 determine-if-two-strings-are-close

26개의 크기의 0으로 채워진 배열을 사용하여 알파벳 각각의 카운트를 센다. 문제 조건에 따라 문자 occurrence만 같으면 횟수는 섞여도 상관 없기 때문에 첫번째 if문에서와 같이 써도 된다.

  for (let i = 0; i < 26; ++i) {
    if ((kind1[i] === 0 && kind2[i] > 0) || (kind1[i] > 0 && kind2[i] === 0)) {
      return false;
    }
  }

두 히스토그램으로부터 정렬한 결과가 일치한다면, 같은 횟수들로만 이루어져있음을 의미하므로 두번째 if문은 다음과 같이 쓸 수 있다.

  kind1.sort((a, b) => a - b);
  kind2.sort((a, b) => a - b);
  for (let i = 0; i < 26; ++i) {
    if (kind1[i] !== kind2[i]) {
      return false;
    }
  }

leet 1732 find-the-highest-altitude

그냥 미분한 배열을 입력으로 주고 0부터 직접 더해가며 최대값을 찾기만 함 된다.

@ChoiWheatley ChoiWheatley merged commit 6175239 into Jungle-7-Algorithm-study:main Feb 24, 2024
@ChoiWheatley ChoiWheatley deleted the leet-1657-1732 branch February 24, 2024 11:35
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.

None yet

2 participants