06 2015 档案
摘要:Given a sorted integer array without duplicates, return the summary of its ranges.For example, given[0,1,2,4,5,7], return["0->2","4->5","7"].类似于 Leetc...
阅读全文
摘要:Suppose that a website contains two tables, theCustomerstable and theOrderstable. Write a SQL query to find all customers who never order anything.Tab...
阅读全文
摘要:+----+---------+| Id | Email |+----+---------+| 1 | a@b.com || 2 | c@d.com || 3 | a@b.com |+----+---------+For example, your query should return ...
阅读全文
摘要:TheEmployeetable holds all employees including their managers. Every employee has an Id, and there is also a column for the manager Id.+----+-------+-...
阅读全文
摘要:Table:Person+-------------+---------+| Column Name | Type |+-------------+---------+| PersonId | int || FirstName | varchar || LastName ...
阅读全文
摘要:Given an array of integers, find if the array contains any duplicates. Your function should return true if any value appears at least twice in the arr...
阅读全文
摘要:Given an array of integers and an integerk, find out whether there there are two distinct indicesiandjin the array such thatnums[i] = nums[j]and the d...
阅读全文
摘要:Given a string containing just the characters'(',')','{','}','['and']', determine if the input string is valid.The brackets must close in the correct ...
阅读全文
摘要:Given two stringssandt, determine if they are isomorphic.Two strings are isomorphic if the characters inscan be replaced to gett.All occurrences of a ...
阅读全文
摘要:Write a function to find the longest common prefix string amongst an array of strings. 直接按第一个元素开始比较,最后截取符合要求的前段。 Python版本
阅读全文
摘要:Given a linked list, swap every two adjacent nodes and return its head.For example,Given1->2->3->4, you should return the list as2->1->4->3.Your algor...
阅读全文
摘要:Reverse a linked list from positionmton. Do it in-place and in one-pass.For example:Given1->2->3->4->5->NULL,m= 2 andn= 4,return1->4->3->2->5->NULL.No...
阅读全文
摘要:Given an array where elements are sorted in ascending order, convert it to a height balanced BST. 数组中间值置为root,然后对于两边的两块数组再调用该函数。
阅读全文
摘要:Given a singly linked list where elements are sorted in ascending order, convert it to a height balanced BST.链表转换为BST,找到最中间的node设置为树的root,然后截断(设null),...
阅读全文
摘要:创建正则表达式var re = new RegExp('parameter1','parameter2');var re = /parameter1/parameter2;g 全文查找,icase-insensitive,m 多行查找var re = new RegExp('a','gi');// ...
阅读全文
摘要:Rat AttackInput:standard inputOutput:standardoutputTime Limit:7 secondsMemory Limit:32 MBBaaaam! Another deadly gas bomb explodes in Manhattan’sunderw...
阅读全文
摘要:A. Theatre SquareTheatre Square in the capital city of Berland has a rectangular shape with the sizen × mmeters. On the occasion of the city's anniver...
阅读全文
摘要:Remove all elements from a linked list of integers that have valueval.ExampleGiven:1 --> 2 --> 6 --> 3 --> 4 --> 5 --> 6,val= 6Return:1 --> 2 --> 3 --...
阅读全文
摘要:Given a sorted linked list, delete all duplicates such that each element appear onlyonce.For example,Given1->1->2, return1->2.Given1->1->2->3->3, retu...
阅读全文
摘要:Write a SQL query to delete all duplicate email entries in a table namedPerson, keeping only unique emails based on itssmallestId.+----+--------------...
阅读全文
摘要:Given aWeathertable, write a SQL query to find all dates' Ids with higher temperature compared to its previous (yesterday's) dates.+---------+--------...
阅读全文
摘要:You are a professional robber planning to rob houses along a street. Each house has a certain amount of money stashed, the only constraint stopping yo
阅读全文
摘要:Given a sorted array and a target value, return the index if the target is found. If not, return the index where it would be if it were inserted in or...
阅读全文
摘要:Given an array of sizen, find the majority element. The majority element is the element that appears more than⌊ n/2 ⌋times.You may assume that the arr...
阅读全文
摘要:Print all palindromes of size greater than or equal to 3 of a given string.动态规划: p[j] 表示对于(i-1..j)这一段的字符串是否为回文。所以要使p[j] 为1的条件是中间的字符串(i-1..j-1)为回文(p[j-...
阅读全文
摘要:Given a linked list and a value x, partition it such that all nodes less than x come before nodes greater than or equal to x. You should preserve the
阅读全文
摘要:Given an index k, return the kth row of the Pascal's triangle. For example, given k = 3,Return [1,3,3,1]. 也可以和 Leetcode 118 Pascal's Triangle II 一样构造最
阅读全文
摘要:Given numRows, generate the first numRows of Pascal's triangle. For example, given numRows = 5,Return 转移方程 p[i][j] = p[i-1][j-1] + p[i-1][j] 或者每次手动构造下
阅读全文
摘要:Given a triangle, find the minimum path sum from top to bottom. Each step you may move to adjacent numbers on the row below. For example, given the fo
阅读全文
摘要:Determine whether an integer is a palindrome. Do this without extra space.利用余数构造倒置数再判断。var isPalindrome = function(x) { var y = 0 var t = x w...
阅读全文
摘要:Reverse digits of an integer.Example1:x = 123, return 321Example2:x = -123, return -321这里转成字符后倒置后转回数字。var reverse = function(x) { function rev(n){ ...
阅读全文
摘要:Given an array of integers, every element appearsthreetimes except for one. Find that single one.Note:Your algorithm should have a linear runtime comp...
阅读全文
摘要:Given a linked list, return the node where the cycle begins. If there is no cycle, returnnull.Follow up:Can you solve it without using extra space?同Le...
阅读全文
摘要:Given a linked list, determine if it has a cycle in it.Follow up:Can you solve it without using extra space?LL经典题:一个指针每次前进1node,另一个指针每次前进2node,如果有环则必会...
阅读全文
摘要:Given an array of integers, every element appearstwiceexcept for one. Find that single one.传统方法:使用Hash,扫描一遍如果Hash中没有这个元素则加入,否则从Hash中删除,最后Hash中留有一个单独的元...
阅读全文
摘要:Given two binary trees, write a function to check if they are equal or not.Two binary trees are considered equal if they are structurally identical an...
阅读全文
摘要:Data Types5 Data Typesstring, number, boolean, object, function3 Object Typesobject, array, date2 Other Typesnull, undefinedType ConversionNumber/Bool...
阅读全文
摘要:*稳定指原本数列中相同的元素的相对前后位置在排序后不会被打乱快速排序(n*lgn 不稳定):数组中随机选取一个数x(这里选择最后一个),将数组按比x大的和x小的分成两部分,再对剩余两部分重复这个算法直到结束。但在数据量小的时候表现差。def quick_sort(a) (x = a.pop) ? ...
阅读全文
摘要:Reverse链表。使用三个指针head,a,b,最后head会指向最后一个node,故直接返回head。x -> x -> x -> x => x x => x x => x <- x <- x xh a b a.next = head ...
阅读全文
摘要:求两个字符串中最长的公共部分的长度长宽为对应两个字符串长度的二维数组dpdp[i][j] = x 表示在s1[i]和s2[j]的位置上,已经有长度为x的公共字串if s1[i] == s2[j] 转移方程为dp[i][j] = dp[i-1][j-1] + 1 注意当一边的下标为0时,dp[i]...
阅读全文
摘要:Given an array withnobjects colored red, white or blue, sort them so that objects of the same color are adjacent, with the colors in the order red, wh...
阅读全文
摘要:全称Open Systems Interconnection Model分为 7 层7 Application Data HTTP协议6 Presentation Data ASCII码5 Session Data RPC协议4 Transport Segments TCP/IP协议...
阅读全文
摘要:Given a sorted (increasing order) array, write an algorithm to create a binary tree with minimal height.1.Divide the array equally into left part and ...
阅读全文
摘要:Given a digit string, return all possible letter combinations that the number could represent.A mapping of digit to letters (just like on the telephon...
阅读全文
摘要:Given an arraySofnintegers, find three integers inSsuch that the sum is closest to a given number, target. Return the sum of the three integers. You m...
阅读全文
摘要:Given an arraySofnintegers, are there elementsa,b,cinSsuch thata+b+c= 0? Find all unique triplets in the array which gives the sum of zero.Note:Elemen...
阅读全文
摘要:Given a binary tree, determine if it is height-balanced.For this problem, a height-balanced binary tree is defined as a binary tree in which the depth...
阅读全文
摘要:Given a binary tree, determine if it is height-balanced.For this problem, a height-balanced binary tree is defined as a binary tree in which the depth...
阅读全文
摘要: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 l
阅读全文
摘要:Given a binary tree, find its maximum depth.The maximum depth is the number of nodes along the longest path from the root node down to the farthest le...
阅读全文
摘要:Given a binary tree, return thepostordertraversal of its nodes' values.For example:Given binary tree{1,#,2,3}, 1 \ 2 / 3return[3,2,1].No...
阅读全文
摘要:Given a binary tree, return thepreordertraversal of its nodes' values.For example:Given binary tree{1,#,2,3}, 1 \ 2 / 3return[1,2,3].Not...
阅读全文
摘要:Given a binary tree, return theinordertraversal of its nodes' values.For example:Given binary tree{1,#,2,3}, 1 \ 2 / 3return[1,3,2].Note...
阅读全文
摘要:Find the seed of a number.Eg : 1716 = 143*1*4*3 =1716 so 143 is the seed of 1716. find all possible seed for a given number.辗转相除法,由性质可利用 sqrt(num) <= ...
阅读全文
摘要: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
阅读全文
摘要:Something cost $10.25 and the customer pays with a $20 bill, the program will print out the most efficient "change-breakdown" which is 1 five, 4 ones,...
阅读全文
摘要:A number is called 'desirable' if all thedigits are strictly ascending eg: 159 as 1<5<9. You know that your rivalhas a strictly numeric password that ...
阅读全文
摘要:You are given a grid of numbers. A snakes equence is made up of adjacent numbers such that for each number, the number on the right or the number belo...
阅读全文
摘要:N*N matrix is given with input red or black.You can move horizontally, vertically or diagonally. If 3 consecutive samecolor found, that color will get...
阅读全文
摘要:Let the user enter a decimal number. Therange allowed is 0.0001 to 0.9999. Only four decimal places are allowed. Theoutput should be an irreducible fr...
阅读全文
摘要:Given aNXN matrix, starting from the upper right corner of the matrix start printingvalues in a counter-clockwise fashion.E.g.: Consider N = 4Matrix= ...
阅读全文
摘要:Invert a binary tree. 4 / \ 2 7 / \ / \1 3 6 9to 4 / \ 7 2 / \ / \9 6 3 1递归实现def invert_tree(root) root.right...
阅读全文
摘要:Given a string s and a dictionary of words dict, determine if s can be segmented into a space-separated sequence of one or more dictionary words. For
阅读全文
摘要:Find the total area covered by tworectilinearrectangles in a2Dplane.Each rectangle is defined by its bottom left corner and top right corner as shown ...
阅读全文
摘要: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()...
阅读全文
摘要:here are a total ofncourses you have to take, labeled from0ton - 1.Some courses may have prerequisites, for example to take course 0 you have to first...
阅读全文
摘要:There are a total of n courses you have to take, labeled from 0 to n - 1. Some courses may have prerequisites, for example to take course 0 you have t
阅读全文
摘要:Given a string, find the length of the longest substring without repeating characters. For example, the longest substring without repeating letters fo...
阅读全文
摘要:You are given two linked lists representing two non-negative numbers. The digits are stored in reverse order and each of their nodes contain a single
阅读全文
摘要:Given an array of integers, find two numbers such that they add up to a specific target number.The function twoSum should return indices of the two nu...
阅读全文
摘要:Given a 2d grid map of'1's (land) and'0's (water), count the number of islands. An island is surrounded by water and is formed by connecting adjacent ...
阅读全文