Skip to content

Solve ch3 problems#22

Merged
rekyungmin merged 1 commit intomasterfrom
km/ch3
Feb 14, 2022
Merged

Solve ch3 problems#22
rekyungmin merged 1 commit intomasterfrom
km/ch3

Conversation

@rekyungmin
Copy link
Copy Markdown
Contributor

No description provided.

@rekyungmin
Copy link
Copy Markdown
Contributor Author

@yongki150 @beombu @JiYongKim-A

@rekyungmin
Copy link
Copy Markdown
Contributor Author

rekyungmin commented Feb 12, 2022

NOTE:

707-design-linked-list 문제를 doubly linked list로 접근한 까닭은 AddAtTail 의 time complexity를 AddAtHead와 동일하게 맞추기 위함입니다. length attribute는 예외 조건 체크와 편의성을 위해 추가하였습니다.

실무적인 관점에서 접근하여 풀이한 것인데,
빠른 풀이에 집중하고 싶다면 데이터스트럭처를 singly linked list로 결정하고� length attribute를 제거하면 됩니다.

Copy link
Copy Markdown
Contributor

@kimdev0206 kimdev0206 left a comment

Choose a reason for hiding this comment

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

난이도업 되기 전 풀이와 난이도업 이후 풀이의 차이로
시·공간 복잡도를 찾아내는 능력을 키울수 있었습니다.

Copy link
Copy Markdown
Contributor

@kimdev0206 kimdev0206 left a comment

Choose a reason for hiding this comment

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

1290번Show Hint 2에서 다음과 같은 난이도업이 제시되어 있어 알려드립니다.

You can solve the problem in O(1) memory using bits operation.
use shift left operation ( << ) and
or operation ( | ) to get the decimal value in one operation.

or 연산 또한 필요하다고 합니다.

@rekyungmin
Copy link
Copy Markdown
Contributor Author

1290번Show Hint 2에서 다음과 같은 난이도업이 제시되어 있어 알려드립니다.

You can solve the problem in O(1) memory using bits operation.
use shift left operation ( << ) and
or operation ( | ) to get the decimal value in one operation.
or 연산 또한 필요하다고 합니다.

네 bitwise or을 사용하면 CPU 레벨의 계산에서 조금 더 이점이 있을 순 있지만,
여기선 + 연산을 쓰는게 더 직관적이라 생각하여 그렇게 사용했습니다.
풀이의 time complexity와 space complexity에는 변화가 없기 때문에 기호에 따라서 풀면 될 듯 합니다.
같은 맥락으로 다음과 같이 풀이해도 무방하다고 봅니다:

result = result * 2 + node.val

@rekyungmin rekyungmin merged commit 1a58d56 into master Feb 14, 2022
@kimdev0206 kimdev0206 deleted the km/ch3 branch April 30, 2022 07:56
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.

4 participants