공부/Algorithm7 [HackerRank] Equal stacks [HackerRank] Equal stacks 문제 링크 https://www.hackerrank.com/challenges/equal-stacks/problem?isFullScreen=true 시간복잡도: O(n) 코드 def equalStacks(h1, h2, h3): sumH1 = sum(h1) sumH2 = sum(h2) sumH3 = sum(h3) while 1: minNum=min(sumH1, sumH2, sumH3) if(sumH1==sumH2==sumH3): #equal? break if(sumH1 > minNum): #sum > min? sumH1 -= h1.pop(0) if(sumH2 > minNum): sumH2 -= h2.pop(0) if(sumH3 > minNum): sumH3 -.. 2022. 3. 8. [HackerRank] Merge two sorted linked lists [HackerRank] Merge two sorted linked lists 문제 링크 https://www.hackerrank.com/challenges/merge-two-sorted-linked-lists/problem?isFullScreen=true 시간복잡도: O(n) 코드 def mergeLists(head1, head2): start =SinglyLinkedListNode(0) end = start while 1: #end while condition if(head1 == None): end.next=head2 break if(head2 == None): end.next=head1 break #compare if head1.data > head2.data: end.next = head2 hea.. 2022. 3. 7. 이전 1 2 다음