#1 2SUM #2 No Division Multiplying

2020. 8. 7. 15:19PS/도전

All problems are from https://www.dailycodingproblem.com/

 

Solution Codes : https://github.com/Kusin/DailyCoding

 

Kusin/DailyCoding

DailyCodingProblem. Contribute to Kusin/DailyCoding development by creating an account on GitHub.

github.com

#1

Approach 1 : Sort and Bianry search O(N log N)

sort arr

for k in arr -> find (Goal-k) in arr by binary sort

 

Approach 2 : Use Hash, O(N)

for k in arr -> hash k

for k in arr -> find (Goal-k) in arr by Hash

 

#2

Approach 1 : O(N^2) , calculate every product

 

Better Approach : Use Prefix, Suffix Array. O(N) Preprocess, and calculate by O(N)

 

728x90