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} s | |
| * @return {number} | |
| */ | |
| var firstUniqChar = function(s) { | |
| var result = -1; | |
| var hash = {}; | |
| for (var i=0; i<s.length; i++) { | |
| if (hash[s[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
| // Simple function to add a menu option to the spreadsheet "Export", for saving a PDF of the spreadsheet directly to Google Drive. | |
| // The exported file will be named: SheetName and saved in the same folder as the spreadsheet. | |
| // To change the filename, just set pdfName inside generatePdf() to something else. | |
| // Running this, sends the currently open sheet, as a PDF attachment | |
| function onOpen() { | |
| var submenu = [{name:"Save PDF", functionName:"generatePdf"}]; | |
| SpreadsheetApp.getActiveSpreadsheet().addMenu('Export', submenu); | |
| } |
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 Solution { | |
| private: | |
| bool isCapital(char ch) { | |
| return ((int)ch >= 65 && (int)ch <= 90); | |
| } | |
| public: | |
| bool detectCapitalUse(string word) { | |
| bool result = true; | |
| bool foundLower = 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
| /** | |
| * Definition for a binary tree node. | |
| * function TreeNode(val) { | |
| * this.val = val; | |
| * this.left = this.right = null; | |
| * } | |
| */ | |
| /** | |
| * @param {TreeNode} root | |
| * @return {number} |
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 Hello extends React.Component { | |
| constructor(props) { | |
| super(props); | |
| this.state = { | |
| name: null, | |
| count: 0 | |
| }; | |
| this.onChange = this.onChange.bind(this); |
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
| <!DOCTYPE html> | |
| <html> | |
| <head> | |
| <meta charset="utf-8"> | |
| <meta name="viewport" content="width=device-width"> | |
| <title>JS Bin</title> | |
| <script src="https://code.jquery.com/jquery.min.js"></script> | |
| <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet" type="text/css" /> | |
| <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script> | |
| <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.0/angular.min.js"></script> |
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
| <!-- Demo at http://jsbin.com/zejuvo/1/edit?html,js,output --> | |
| <!DOCTYPE html> | |
| <html> | |
| <head> | |
| <meta charset="utf-8"> | |
| <meta name="viewport" content="width=device-width"> | |
| <title>JS Bin</title> | |
| <script src="https://code.jquery.com/jquery.min.js"></script> | |
| <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet" type="text/css" /> | |
| <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script> |
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 getInvalidCount(arr) { | |
| // Count the number of invalid positions in a sorted array. | |
| var result = 0; | |
| for (var i=0; i<arr.length; i++) { | |
| if (arr[i] !== i+1) { | |
| result++; | |
| } | |
| } | |
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
| /* Method 1: Calculate the next multiple of 5 from the grade. | |
| Do this by getting the tens digit of the grade, and then determining if +5 or +10 is closer to the grade. | |
| Then simply calculate the difference and add to the grade. | |
| O(1) | |
| */ | |
| function main() { | |
| var n = parseInt(readLine()); | |
| for(var a0 = 0; a0 < n; a0++){ | |
| var grade = parseInt(readLine()); | |
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 the end of a linked list | |
| head pointer input could be NULL as well for empty list | |
| Node is defined as | |
| class Node { | |
| int data; | |
| Node next; | |
| Node prev; | |
| } | |
| */ |