"HR30 Day 18: Queues and Stacks"의 두 판 사이의 차이

잔글 (봇: 자동으로 텍스트 교체 (-</source> +</syntaxhighlight>, -<source +<syntaxhighlight ))
 
9번째 줄: 9번째 줄:
==Java==
==Java==
{{참고|HR30 Day 18: Queues and Stacks/Java}}
{{참고|HR30 Day 18: Queues and Stacks/Java}}
<source lang='Java'>
<syntaxhighlight lang='Java'>
public class Solution {
public class Solution {
     // Write your code here.
     // Write your code here.
26번째 줄: 26번째 줄:
         return queue.remove();
         return queue.remove();
     }
     }
</source>
</syntaxhighlight>


==PHP==
==PHP==
{{참고|HR30 Day 18: Queues and Stacks/PHP}}
{{참고|HR30 Day 18: Queues and Stacks/PHP}}
<source lang='PHP'>
<syntaxhighlight lang='PHP'>
class Solution {
class Solution {
     // Write your code here
     // Write your code here
48번째 줄: 48번째 줄:
     }
     }
}
}
</source>
</syntaxhighlight>
<source lang='php'>
<syntaxhighlight lang='php'>
class Solution {
class Solution {
     // Write your code here
     // Write your code here
71번째 줄: 71번째 줄:
     }
     }
}
}
</source>
</syntaxhighlight>


==Python==
==Python==
{{참고|HR30 Day 18: Queues and Stacks/Python}}
{{참고|HR30 Day 18: Queues and Stacks/Python}}
<source lang='Python'>
<syntaxhighlight lang='Python'>
class Solution(object):
class Solution(object):
     # Write your code here
     # Write your code here
89번째 줄: 89번째 줄:
     def dequeueCharacter(self):
     def dequeueCharacter(self):
         return self.queue.pop()
         return self.queue.pop()
</source>
</syntaxhighlight>

2021년 7월 31일 (토) 10:34 기준 최신판

1 개요[ | ]

HR30 Day 18: Queues and Stacks
해커랭크 30 Days of Code
문제 풀이
10-19 Day e
HR30 Day 10: Binary Numbers

HR30 Day 11: 2D Arrays

HR30 Day 12: Inheritance

HR30 Day 13: Abstract Classes

HR30 Day 14: Scope

HR30 Day 15: Linked List

HR30 Day 16: Exceptions - String to Integer

HR30 Day 17: More Exceptions

HR30 Day 18: Queues and Stacks

HR30 Day 19: Interfaces

2 Java[ | ]

public class Solution {
    // Write your code here.
    private Stack<Character> stack = new Stack<Character>();
    private Queue<Character> queue = new LinkedList<Character>();
    void pushCharacter(char ch) {
        stack.push(ch);
    }
    void enqueueCharacter(char ch) {
        queue.add(ch);
    }
    char popCharacter() {
        return stack.pop();
    }
    char dequeueCharacter() {
        return queue.remove();
    }

3 PHP[ | ]

class Solution {
    // Write your code here
    private $stack = [];
    private $queue = [];
    function pushCharacter($ch) {
        array_push($this->stack, $ch);
    }
    function enqueueCharacter($ch) {
        array_push($this->queue, $ch);
    }
    function popCharacter() {
        return array_pop($this->stack);
    }
    function dequeueCharacter() {
        return array_shift($this->queue);
    }
}
class Solution {
    // Write your code here
    private $stack;
    private $queue;
    function __construct() {
        $this->stack = new SplStack();
        $this->queue = new SplQueue(); 
    }
    function pushCharacter($ch) {
        $this->stack->push($ch);
    }
    function enqueueCharacter($ch) {
        $this->queue->enqueue($ch);
    }
    function popCharacter() {
        return $this->stack->pop();
    }
    function dequeueCharacter() {
        return $this->queue->dequeue();
    }
}

4 Python[ | ]

class Solution(object):
    # Write your code here
    def __init__(self):
        self.stack = []
        self.queue = []
    def pushCharacter(self, ch):
        self.stack.append(ch)
    def enqueueCharacter(self, ch):
        self.queue.insert(0, ch)
    def popCharacter(self):
        return self.stack.pop()
    def dequeueCharacter(self):
        return self.queue.pop()
문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}