Leetcode Easy Javascript
文章平均质量分 69
RockPaperProgrammer
Github: https://github.com/didi0613
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
Intersection of Two Linked List -JS
Write a program to find the node at which the intersection of two singly linked lists begins.For example, the following two linked lists:A: a1 → a2 ↘原创 2016-06-16 10:39:42 · 283 阅读 · 0 评论 -
Reverse Integer - Javacript
Reverse digits of an integer.Example1: x = 123, return 321Example2: x = -123, return -321TagMath------------------------------------------------------------------------------------------原创 2016-06-15 09:56:02 · 271 阅读 · 0 评论 -
Valid Palindrome
Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignoring cases.For example,"A man, a plan, a canal: Panama" is a palindrome."race a car" is not a原创 2016-06-15 09:14:56 · 300 阅读 · 0 评论 -
Implement strStr() - Javascript
Implement strStr().Returns the index of the first occurrence of needle in haystack, or -1 if needle is not part of haystack.TagsTwo Pointers, String------------------------------------原创 2016-06-15 06:30:31 · 666 阅读 · 0 评论 -
Add Binary - Javacript
Given two binary strings, return their sum (also a binary string).For example,a = "11"b = "1"Return "100".TagMath, String-------------------------------------------------------------原创 2016-06-15 06:29:02 · 239 阅读 · 0 评论 -
Longest Common Prefix - Javacript
Write a function to find the longest common prefix string amongst an array of strings.TagsString--------------------------------------------------------------------------------------------原创 2016-06-15 06:03:49 · 405 阅读 · 0 评论 -
Two Sum
Given an array of integers, return indices of the two numbers such that they add up to a specific target.You may assume that each input would have exactly one solution.Example:Given nums =原创 2016-06-15 04:04:09 · 207 阅读 · 0 评论 -
String to Integer (atoi)
Implement atoi to convert a string to an integer.Hint: Carefully consider all possible input cases. If you want a challenge, please do not see below and ask yourself what are the possible input ca原创 2016-06-14 23:56:10 · 198 阅读 · 0 评论 -
Valid Sudoku - Javacript
Determine if a Sudoku is valid, according to: Sudoku Puzzles - The Rules.The Sudoku board could be partially filled, where empty cells are filled with the character '.'.A partially fille原创 2016-06-14 15:00:41 · 347 阅读 · 0 评论 -
Contains Duplicate II
Given an array of integers and an integer k, find out whether there are two distinct indices i and j in the array such that nums[i] = nums[j] and the difference between i and j is at most k.原创 2016-06-14 13:58:59 · 226 阅读 · 0 评论 -
Factorial Trailing Zeroes - Javacript
Given an integer n, return the number of trailing zeroes in n!.Note: Your solution should be in logarithmic time complexity.Credits:Special thanks to @ts for adding this problem and creating原创 2016-06-14 13:38:18 · 265 阅读 · 0 评论 -
Minimum Depth of Binary Tree - Javascript
Given a binary tree, find its minimum depth.The minimum depth is the number of nodes along the shortest path from the root node down to the nearest leaf node.TagsBFS, DFS, Tree--------原创 2016-06-14 08:17:31 · 469 阅读 · 0 评论 -
Implement stack using queue
Implement the following operations of a stack using queues.push(x) -- Push element x onto stack.pop() -- Removes the element on top of the stack.top() -- Get the top element.empty() -- Return whet原创 2016-06-14 07:54:14 · 275 阅读 · 0 评论 -
Path Sum
Given a binary tree and a sum, determine if the tree has a root-to-leaf path such that adding up all the values along the path equals the given sum.For example:Given the below binary tree and sum原创 2016-06-14 07:26:14 · 199 阅读 · 0 评论 -
Palindrome Number
Determine whether an integer is a palindrome. Do this without extra space.TagsMath----------------------------------------------------------------------------------------------------------原创 2016-06-14 06:40:21 · 198 阅读 · 0 评论 -
Pascal's Triangle II
Given an index k, return the kth row of the Pascal's triangle.For example, given k = 3,Return [1,3,3,1].Note:Could you optimize your algorithm to use only O(k) extra space?TagsArray原创 2016-06-14 06:34:41 · 204 阅读 · 0 评论 -
First Bad Version - Javascript
You are a product manager and currently leading a team to develop a new product. Unfortunately, the latest version of your product fails the quality check. Since each version is developed based on the原创 2016-06-15 10:16:21 · 281 阅读 · 0 评论 -
Range Sum Query - Javacript
Given an integer array nums, find the sum of the elements between indices i and j (i ≤ j), inclusive.Example:Given nums = [-2, 0, 3, -5, 2, -1]sumRange(0, 2) -> 1sumRange(2, 5) -> -1sumRan原创 2016-06-15 12:38:51 · 253 阅读 · 0 评论 -
Excel Sheet Column Title
Given a positive integer, return its corresponding column title as appear in an Excel sheet.For example: 1 -> A 2 -> B 3 -> C ... 26 -> Z 27 -> AA 28 -> AB Credits原创 2016-06-15 12:50:32 · 228 阅读 · 0 评论 -
Rotate Array - Javacript
Rotate an array of n elements to the right by k steps.For example, with n = 7 and k = 3, the array [1,2,3,4,5,6,7] is rotated to [5,6,7,1,2,3,4].Note:Try to come up as many solutions as yo原创 2016-06-15 14:31:26 · 289 阅读 · 0 评论 -
Bulls and Cows - JS
You are playing the following Bulls and Cows game with your friend: You write down a number and ask your friend to guess what the number is. Each time your friend makes a guess, you provide a hint t原创 2016-06-16 10:17:12 · 494 阅读 · 0 评论 -
Merge Sorted Array
Given two sorted integer arrays nums1 and nums2, merge nums2 into nums1 as one sorted array.Note:You may assume that nums1 has enough space (size that is greater or equal to m + n) to hold addit原创 2016-06-16 08:55:15 · 276 阅读 · 0 评论 -
Isomorphic Strings - Javacript
Given two strings s and t, determine if they are isomorphic.Two strings are isomorphic if the characters in s can be replaced to get t.All occurrences of a character must be replaced with anot原创 2016-06-16 08:43:51 · 381 阅读 · 0 评论 -
Remove Nth Node From End of List - JS
Given a linked list, remove the nth node from the end of list and return its head.For example, Given linked list: 1->2->3->4->5, and n = 2. After removing the second node from the end, the原创 2016-06-16 08:30:06 · 249 阅读 · 0 评论 -
Word Pattern - JS
Given a pattern and a string str, find if str follows the same pattern.Here follow means a full match, such that there is a bijection between a letter in pattern and a non-empty word in str.原创 2016-06-16 08:16:01 · 282 阅读 · 0 评论 -
Length of Last Word
Given a string s consists of upper/lower-case alphabets and empty space characters ' ', return the length of last word in the string.If the last word does not exist, return 0.Note: A word is原创 2016-06-16 07:51:31 · 216 阅读 · 0 评论 -
Count and Say - JS
The count-and-say sequence is the sequence of integers beginning as follows:1, 11, 21, 1211, 111221, ...1 is read off as "one 1" or 11.11 is read off as "two 1s" or 21.21 is read off as原创 2016-06-16 07:47:10 · 287 阅读 · 0 评论 -
Binary Tree Paths - Javascript
Given a binary tree, return all root-to-leaf paths.For example, given the following binary tree: 1 / \2 3 \ 5All root-to-leaf paths are:["1->2->5", "1->3"]Cre原创 2016-06-16 06:56:42 · 416 阅读 · 0 评论 -
Binary Tree Paths - JS
Given a binary tree, return all root-to-leaf paths.For example, given the following binary tree: 1 / \2 3 \ 5All root-to-leaf paths are:["1->2->5", "1->3"]Cre原创 2016-06-16 03:58:30 · 458 阅读 · 0 评论 -
Remove Linked List Elements - JS
Remove all elements from a linked list of integers that have value val.ExampleGiven: 1 --> 2 --> 6 --> 3 --> 4 --> 5 --> 6, val = 6Return: 1 --> 2 --> 3 --> 4 --> 5Credits:Special thanks原创 2016-06-16 03:29:50 · 323 阅读 · 0 评论 -
Palindrome Linked List - JS
Given a singly linked list, determine if it is a palindrome.Follow up:Could you do it in O(n) time and O(1) space?Subscribe to see which companies asked this questionTagLinkedList, T原创 2016-06-16 03:18:31 · 423 阅读 · 0 评论 -
Count Primes - Javascript
Description:Count the number of prime numbers less than a non-negative number, n.Credits:Special thanks to @mithmatt for adding this problem and creating all test cases.TagsHash Table,原创 2016-06-15 14:20:05 · 1146 阅读 · 0 评论 -
ZigZag Conversion - Javascript
The string "PAYPALISHIRING" is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a fixed font for better legibility)P A H NA P L S I原创 2016-06-15 13:57:06 · 652 阅读 · 0 评论 -
Compare Version Numbers
Compare two version numbers version1 and version2.If version1 > version2 return 1, if version1 version2 return -1, otherwise return 0.You may assume that the version strings are non-empty and co原创 2016-06-15 13:32:34 · 520 阅读 · 0 评论 -
Binary Tree Level Order Tranversal
Given a binary tree, return the level order traversal of its nodes' values. (ie, from left to right, level by level).For example:Given binary tree [3,9,20,null,null,15,7], 3 / \ 9 2原创 2016-06-14 05:25:46 · 270 阅读 · 0 评论 -
Remove Duplicates from Sorted Array
Given a sorted array, remove the duplicates in place such that each element appear only once and return the new length.Do not allocate extra space for another array, you must do this in place with原创 2016-06-14 05:14:56 · 302 阅读 · 0 评论 -
Pascal's Triangle
Given numRows, generate the first numRows of Pascal's triangle.For example, given numRows = 5,Return[ [1], [1,1], [1,2,1], [1,3,3,1], [1,4,6,4,1]]TagsArray----原创 2016-06-14 05:12:59 · 196 阅读 · 0 评论 -
Lowest Common Ancestor of a Binary Search Tree
Given a binary search tree (BST), find the lowest common ancestor (LCA) of two given nodes in the BST.According to the definition of LCA on Wikipedia: “The lowest common ancestor is defined betw原创 2016-06-11 04:51:36 · 159 阅读 · 0 评论 -
Roman to Integer
Given a roman numeral, convert it to an integer.Input is guaranteed to be within the range from 1 to 3999.Tags:Math, String-------------------------------------------------------------原创 2016-06-11 04:39:57 · 176 阅读 · 0 评论 -
Reverse Linked List
Reverse a singly linked list.TagsLinkedList-------------------------------------------------------------------------------------------------------------------------------------------------原创 2016-06-11 04:11:32 · 186 阅读 · 0 评论
分享