This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from typing import Optional | |
| # optional is used for type hinting when a variable can be of a certain type or None | |
| # i.e. Optional[Item] means the variable can be an Item instance or None, which | |
| # is useful for representing empty slots in the vending machine | |
| # this program can be simplified a lot, but is structured this way to demonstrate | |
| # some object-oriented programming concepts | |
| class Item: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // The question: | |
| // Some numbers can be made out of a summation of positive consecutive numbers | |
| // Examples: | |
| // 1+2+3 = 6 | |
| // 2+3+4 = 9 | |
| // 3+4+5+6 = 18 | |
| // | |
| // Write a function that takes in an integer and returns a boolean if that number can be made out of a summation of consecutive numbers. | |
| // -------------------------- | |
| // First thought was if there was a pattern of numbers that can or cannot be made out of a summation of consecutive numbers |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import java.util.Stack; | |
| class ParenthesesValidator { | |
| public String parenthesesValidator(String input) { | |
| Stack<Character> parenStack = new Stack<>(); | |
| char[] inputArray = input.toCharArray(); | |
| for (char c : inputArray) { | |
| if (c == '(') { | |
| parenStack.push(c); |