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
| var reverseInt = function(num) | |
| { | |
| var result=0; | |
| while (num > 0) | |
| { | |
| result = (result * 10) + (num % 10); | |
| num = Math.floor(num / 10); | |
| } | |
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
| /** | |
| * @param {number[]} findNums | |
| * @param {number[]} nums | |
| * @return {number[]} | |
| */ | |
| var nextGreaterElement = function(findNums, nums) { | |
| var result = []; | |
| var hash = {}; | |
| for (var i=0; i<findNums.length; i++) { |
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
| /** | |
| * @param {string[]} words | |
| * @return {string[]} | |
| */ | |
| var findWords = function(words) { | |
| var result = []; | |
| var keyboard = {'q':1, 'w':1, 'e':1, 'r':1, 't':1, 'y':1, 'u':1, 'i':1, 'o':1, 'p':1, | |
| 'a':2, 's':2, 'd':2, 'f':2, 'g':2, 'h':2, 'j':2, 'k':2, 'l':2, | |
| 'z':3, 'x':3, 'c':3, 'v':3, 'b':3, 'n':3, 'm':3 |
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 BinaryHeap(scoreFunction){ | |
| this.content = []; | |
| this.scoreFunction = scoreFunction; | |
| } | |
| BinaryHeap.prototype = { | |
| push: function(element) { | |
| // Add the new element to the end of the array. | |
| this.content.push(element); | |
| // Allow it to bubble up. |
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.io.*; | |
| import java.util.*; | |
| import java.text.*; | |
| import java.math.*; | |
| import java.util.regex.*; | |
| public class Solution { | |
| public static void main(String[] args) { | |
| Scanner in = new Scanner(System.in); |
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'); | |
| for (var i=1; i<lines.length; i++) { | |
| var str = lines[i]; | |
| var deleteCount = 0; | |
| for (var j=1; j<str.length; j++) { | |
| // Is a duplicate to the left of this position? | |
| if (str[j-1] === str[j]) { | |
| // Delete. |
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 n = parseInt(lines[0]); | |
| var gems = {}; | |
| var hash = {}; | |
| for (var i=1; i<lines.length; i++) { | |
| var str = lines[i]; | |
| for (var j=0; j<str.length; j++) { |
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'); | |
| for (var i=2; i<lines.length; i+=2) { | |
| var arr = lines[i].split(' ').map(function(x) { return parseInt(x); }); | |
| if (arr.length > 1) { | |
| var sum = 0; | |
| // First, get the sum of the entire array. | |
| for (var j=0; j<arr.length; j++) { |
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'); | |
| for (var i=1; i<lines.length; i++) { | |
| var str = lines[i]; | |
| for (var j=1; j<str.length; j++) { | |
| var diff1 = Math.abs(str.charCodeAt(j) - str.charCodeAt(j-1)); | |
| var diff2 = Math.abs(str.charCodeAt(str.length - j) - str.charCodeAt(str.length - 1 - j)); | |
| if (diff1 !== diff2) { | |
| break; |
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; | |
| }); |