950. Reveal Cards In Increasing Order

알고리즘 문제풀기 · 2020. 1. 26. 10:00

https://leetcode.com/problems/reveal-cards-in-increasing-order/

 

Reveal Cards In Increasing Order - LeetCode

Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview.

leetcode.com

 

카드를 증가하는 순서로 뽑도록 리스트를 reordering하는 문제.

 

문제의 룰을 역순으로 따라가게끔 하면 쉽게 풀 수 있음. medium보단 easy에 가까운것같음

 

 

class Solution(object):
    def deckRevealedIncreasing(self, deck):
        """
        :type deck: List[int]
        :rtype: List[int]
        """
        
        new_list = []
        
        while len(deck) != 0:
            max_value = max(deck)    
            deck.remove(max_value)

            if new_list:
                front = new_list.pop()
                new_list.insert(0,front)                
                new_list.insert(0, max_value)
            else:
                new_list.append(max_value)

        #print(new_list,"NEW_LIST")
        return new_list
    

'알고리즘 문제풀기' 카테고리의 다른 글

120. Triangle  (0) 2020.01.28
39. Combination Sum  (0) 2020.01.28
1277. Count Square Submatrices with All Ones  (0) 2020.01.25
1254. Number of Closed Islands  (0) 2020.01.25
969. Pancake Sorting  (0) 2019.12.11