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
| process.stdin.resume(); | |
| process.stdin.setEncoding('ascii'); | |
| var input_stdin = ""; | |
| var input_stdin_array = ""; | |
| var input_currentline = 0; | |
| process.stdin.on('data', function (data) { | |
| input_stdin += data; | |
| }); |
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
| void ReversePrint(Node head) { | |
| // This is a "method-only" submission. | |
| // You only need to complete this method. | |
| if (head != null) { | |
| ReversePrint(head.next); | |
| System.out.println(head.data); | |
| } | |
| } |
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
| process.stdin.resume(); | |
| process.stdin.setEncoding('ascii'); | |
| var input_stdin = ""; | |
| var input_stdin_array = ""; | |
| var input_currentline = 0; | |
| process.stdin.on('data', function (data) { | |
| input_stdin += data; | |
| }); |
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
| /* This method stores all versions of the string before each operation, allowing undo to a prior saved string. | |
| The drawback to this method is the storage size of the stack, since the entire string is stored each time. */ | |
| function processData(input) { | |
| var lines = input.split('\n'); | |
| var str = ''; | |
| var stack = []; | |
| for (var i=1; i<lines.length; i++) { | |
| var parts = lines[i].split(' '); | |
| var command = parseInt(parts[0]); |
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
| boolean checkBST(Node root) { | |
| return checkBST(root, 0, 10000); | |
| } | |
| boolean checkBST(Node node, int min, int max) { | |
| if (node == null) { | |
| return true; | |
| } | |
| else if (node.data < min || node.data > max) { | |
| return false; |
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
| /* | |
| class Node | |
| int data; | |
| Node left; | |
| Node right; | |
| */ | |
| void LevelOrder(Node root) | |
| { | |
| Queue<Node> fringe = new LinkedList<Node>(); |
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
| Node Delete(Node head, int position) { | |
| if (head == null) { | |
| return null; | |
| } else if (position == 0) { | |
| return head.next; | |
| } else { | |
| Node n = head; | |
| for (int i = 0; i < position - 1; i++) { | |
| n = n.next; | |
| } |
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
| /* | |
| Insert Node at a given position in a linked list | |
| head can be NULL | |
| First element in the linked list is at position 0 | |
| Node is defined as | |
| var Node = function(data) { | |
| this.data = data; | |
| this.next = null; | |
| } | |
| */ |
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
| function processData(input) { | |
| var lines = input.split('\n'); | |
| var k = parseInt(lines[0].split(' ')[1]); | |
| var prices = lines[1].split(' ').map(function(x) { return parseInt(x); }); | |
| var charge = parseInt(lines[2]); | |
| // First, calculate the total that should be split, ignoring item k. | |
| var total = 0; | |
| for (var i = 0; i<prices.length; i++) { | |
| if (i !== k) { |
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
| process.stdin.resume(); | |
| process.stdin.setEncoding('ascii'); | |
| var input_stdin = ""; | |
| var input_stdin_array = ""; | |
| var input_currentline = 0; | |
| process.stdin.on('data', function (data) { | |
| input_stdin += data; | |
| }); |