Skip to content

[DaleSeo] WEEK 1 Solutions#2348

Open
DaleSeo wants to merge 1 commit intomainfrom
week1
Open

[DaleSeo] WEEK 1 Solutions#2348
DaleSeo wants to merge 1 commit intomainfrom
week1

Conversation

@DaleSeo
Copy link
Member

@DaleSeo DaleSeo commented Feb 28, 2026

답안 제출 문제

작성자 체크 리스트

  • Projects의 오른쪽 버튼(▼)을 눌러 확장한 뒤, Week를 현재 주차로 설정해주세요.
  • 문제를 모두 푸시면 프로젝트에서 StatusIn Review로 설정해주세요.
  • 코드 검토자 1분 이상으로부터 승인을 받으셨다면 PR을 병합해주세요.

검토자 체크 리스트

Important

본인 답안 제출 뿐만 아니라 다른 분 PR 하나 이상을 반드시 검토를 해주셔야 합니다!

  • 바로 이전에 올라온 PR에 본인을 코드 리뷰어로 추가해주세요.
  • 본인이 검토해야하는 PR의 답안 코드에 피드백을 주세요.
  • 토요일 전까지 PR을 병합할 수 있도록 승인해주세요.

Copy link

@dohyeon2 dohyeon2 left a comment

Choose a reason for hiding this comment

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

간단한 문제지만, Rust를 재미있게 잘 살펴볼 수 있었습니다.
좋은 풀이 감사합니다.

for (i, &num) in nums.iter().enumerate() {
let complement = target - num;
if let Some(&j) = indices.get(&complement) {
return vec![j as i32, i as i32];

Choose a reason for hiding this comment

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

'이 부분에서 왜 정렬을 안하지?'라고 생각했는데

You can return the answer in any order.

최면에 걸린 것 처럼 정렬을 해버렸는데,,
이런 조건이 있네요.

심지어 순차적으로 조회하며 index를 반환하는거라
정렬을 안해도 결과가 같다는 당연한 사실을 알게되었습니다..

// TC: O(n)
// SC: O(n)
impl Solution {
pub fn two_sum(nums: Vec<i32>, target: i32) -> Vec<i32> {

Choose a reason for hiding this comment

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

Vec<i32>의 의미는 알겠는데,
i32라는 표현이 꽤나 무섭네요.

확실히 다른 인기있는 언어들에 비해 저수준을 다룬다는 걸 알 수 있네요.

pub fn two_sum(nums: Vec<i32>, target: i32) -> Vec<i32> {
let mut indices = HashMap::new();
for (i, &num) in nums.iter().enumerate() {
let complement = target - num;

Choose a reason for hiding this comment

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

complement라는 표현을 알아갑니다.

let mut indices = HashMap::new();
for (i, &num) in nums.iter().enumerate() {
let complement = target - num;
if let Some(&j) = indices.get(&complement) {

Choose a reason for hiding this comment

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

rust의 null참조 방지가 꽤 편리한 것 같습니다.

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

Labels

Projects

Status: In Review

Development

Successfully merging this pull request may close these issues.

2 participants