-
Notifications
You must be signed in to change notification settings - Fork 4
[oh-chaeyeon] 25.01.23 #35
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
Merged
Merged
Conversation
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
JooKangsan
approved these changes
Feb 6, 2025
Collaborator
JooKangsan
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
오픈채팅과 할인행사는 바로이해하면서 보기가 어려워서...나중에 볼게요...! 수고하셨어요!
oh-chaeyeon/4주차_해시/추억_점수.js
Outdated
Collaborator
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
indexOf는 O(n) 시간복잡도를 가져요. 해시맵 사용 시 O(1)로 개선 가능 할 거 같아요!
아래는 예시입니다!
function solution(name, yearning, photo) {
const scoreMap = {};
name.forEach((n, i) => scoreMap[n] = yearning[i]);
return photo.map(p =>
p.reduce((sum, person) => sum + (scoreMap[person] || 0), 0)
);
}
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.
[해시(Hash)]
해시(Hash)란?
해시의 기본 개념
JavaScript 안의 해시
1. 객체(Object) : 키-값 쌍을 저장할 수 있는 기본 자료구조
2. Map : 객체보다 유연하고 효율적인 해시 테이블
해시 관련 Tip!
: 객체는 단순히 키-값 쌍을 저장하는 데 유용하지만, Map은 순서를 보장하고 더 다양한 데이터 타입의 키를 지원하는 차이가 있음.
: 해시를 사용할 때 기본값을 설정하는 습관이 중요하다고 함. -> (frequency[num] || 0)처럼 초기값을 설정해야함.
: 중복 요소를 관리하거나 확인할 때는 Set이 가장 효율적이라고 함
📌 푼 문제
📝 간단한 풀이 과정
모스부호 (1)
A로 B 만들기
진료 순서 정하기
등수 매기기
완주하지 못한 선수
폰켓몬
추억 점수
할인 행사
문제 : 할인 상품 목록 중에서 원하는 모든 물건을 할인받을 수 있는 날짜의 총 일수를 구하는 문제(회원 등록 후 10일간 할인 상품 구매 가능)
required의 역할 : 각 물건별로 필요한 수량을 저장하는 객체
예시) want = ["apple", "banana", "orange"]; number = [3, 2, 1]; -> required = { apple: 3, banana: 2, orange: 1 };
current의 역할 : 현재 10일간 등장한 상품과 그 개수를 저장.
오픈채팅방
늦게 올리게 된점...정말 죄송합니다..