Merged
Conversation
Moonjonghoo
approved these changes
Jan 6, 2025
Collaborator
Moonjonghoo
left a comment
There was a problem hiding this comment.
전반적으로 메서드를 활용해 코드가짜여져있어 깔끔했고,가독성이 좋아서 리뷰하기편했습니다!
한주 고생하셨어요
imchanyo
approved these changes
Jan 7, 2025
Collaborator
|
저는 Math.floor랑 원본 값 을 비교해서 정수를 판별했는데, Number.isInteger라는 정수판별 메서드가 있군요...! |
bona1122
pushed a commit
to bona1122/AlgorithmStudy
that referenced
this pull request
Jan 9, 2025
* 배열 자르기 / 기초 * 배열 원소의 길이 / 기초 * 배열 회전시키기 / 기초 * 중복된 숫자 개수 / 기초 * 제일 작은 수 제거하기 / 중급 * 행렬의 덧셈 / 중급 * 나누어 떨어지는 숫자 배열 / 중급 * 행렬의 곱셈 / 심화 * 교점에 별 만들기 / 심화 * n^2 배열 자르기 / 심화
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
[배열]
배열문제를 풀때, 가장 많이 사용되는 메서드랑 알고리즘들을 노션으로 정리해보았습니다!
📌 푼 문제
📝 간단한 풀이 과정
[기초]
배열 자르기
배열 원소의 길이
배열 회전시키기
( solution([4, 455, 6, 4, -1, 45, 6], "left") -> [455, 6, 4, -1, 45, 6, 4] )
중복된 숫자 개수
[중급]
제일 작은 수 제거하기
Math.min(...arr);사용해서 최솟값을 찾고, filter메서드 사용해서 가장 작은 수를 제외한 배열을 생성해서 반환.행렬의 덧셈
나누어 떨어지는 숫자 배열
[심화]
행렬의 곱셈
행렬의 곱셉 규칙
-> 만약 arr1이 3행렬이고, arr2가 2행렬이라면, 결과는 3행렬이 된다는 이야기...
행렬 곱셉하는 방법
arr1 = [[1, 4], [3, 2], [4, 1]] (3행2열)
arr2 = [[3, 3], [3, 3]] 일때, (2행2열)
result은 3행2열이 될 예정.
result[0][0] = arr1[0][0]*arr2[0][0] + arr1[0][1]*arr2[1][0] = 3 + 12 = 15
result[0][1] = arr1[0][0]*arr2[0][1] + arr1[0][1]*arr2[1][1] = 3 + 12 = 15
result[1][0] = arr1[1][0]*arr2[0][0] + arr1[1][1]*arr2[1][0] = 9 + 6 = 15
result[1][1] = arr1[1][0]*arr2[0][1] + arr1[1][1]*arr2[1][1] = 9 + 6 = 15
result[2][0] = arr1[2][0]*arr2[0][0] + arr1[2][1]*arr2[1][0] = 12 + 3 = 15
result[2][1] = arr1[2][0]*arr2[0][1] + arr1[2][1]*arr2[1][1] = 12 + 3 = 15
결과적으로 result = [[15, 15], [15, 15], [15, 15]] 가 된다,
이게 왜 이렇게 이해하기 어려웠는지,,,
교점에 별 만들기
n^2 배열 자르기
n=3, left=2, right=5일때, 2차원 배열이
1 2 3
2 2 3
3 3 3
이기에, 1차원 배열로 배치하면, [1, 2, 3, 2, 2, 3, 3, 3, 3]으로 결과값은 [3, 2, 2, 3]이 된다.
규칙을 찾는다면,
행(i)과 열(j) 변환: i = Math.floor(k / n) , j = k % n
이를 통해 1차원 인덱스 k를 2차원 좌표 (i, j)로 변환.
값 계산 규칙 : 값 = Math.max(i, j) + 1
행 번호와 열 번호 중 더 큰 값에 1을 더한 것이 배열의 값.
1차원 배열에서 k = 2부터 k = 5까지 규칙대로 계산한다면,
k = 2i = Math.floor(2 / 3) = 0
j = 2 % 3 = 2
Math.max(i, j) + 1 = Math.max(0, 2) + 1 = 3
결과: 3
k = 3i = Math.floor(3 / 3) = 1
j = 3 % 3 = 0
Math.max(i, j) + 1 = Math.max(1, 0) + 1 = 2
결과: 2
k = 4i = Math.floor(4 / 3) = 1
j = 4 % 3 = 1
Math.max(i, j) + 1 = Math.max(1, 1) + 1 = 2
결과: 2
k = 5i = Math.floor(5 / 3) = 1
j = 5 % 3 = 2
Math.max(i, j) + 1 = Math.max(1, 2) + 1 = 3
결과: 3
최종 배열은 [3, 2, 2, 3]이 된다,,
후기
사실 기초, 중급 문제는 8시 전에 풀어놓고 8시에 심화문제 풀기 시작했는데, 심화에서 확 어려워져서 헤맸네요....
그리고 커밋을 영어로 하는걸 보긴 했는데, 문제가 한글이여서 한글로 적었는데 다음부터는 영어로 적어둘게요!