随笔分类 -  LeeCode

摘要:Suppose that a website contains two tables, theCustomerstable and theOrderstable. Write a SQL query to find all customers who never order anything.Tab... 阅读全文
posted @ 2015-07-27 11:12 vpoet 阅读(143) 评论(0) 推荐(0)
摘要:Write a SQL query to find all duplicate emails in a table namedPerson.+----+---------+| Id | Email |+----+---------+| 1 | a@b.com || 2 | c@d.com |... 阅读全文
posted @ 2015-07-27 11:11 vpoet 阅读(148) 评论(0) 推荐(0)
摘要:TheEmployeetable holds all employees including their managers. Every employee has an Id, and there is also a column for the manager Id.+----+-------+-... 阅读全文
posted @ 2015-07-27 11:10 vpoet 阅读(144) 评论(0) 推荐(0)
摘要:Table:Person+-------------+---------+| Column Name | Type |+-------------+---------+| PersonId | int || FirstName | varchar || LastName ... 阅读全文
posted @ 2015-07-27 11:09 vpoet 阅读(139) 评论(0) 推荐(0)
摘要: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... 阅读全文
posted @ 2015-07-20 09:33 vpoet 阅读(174) 评论(0) 推荐(1)
摘要:Rotate an array ofnelements to the right byksteps.For example, withn= 7 andk= 3, the array[1,2,3,4,5,6,7]is rotated to[5,6,7,1,2,3,4].Note:Try to come... 阅读全文
posted @ 2015-07-20 09:32 vpoet 阅读(155) 评论(0) 推荐(0)
摘要:Implementint sqrt(int x).Compute and return the square root ofx. 1 int mySqrt(int x) 2 { 3 if(x==1) 4 return 1; 5 6 /* for(int i=2;i<... 阅读全文
posted @ 2015-07-20 09:31 vpoet 阅读(128) 评论(0) 推荐(0)
摘要: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 --... 阅读全文
posted @ 2015-07-20 09:30 vpoet 阅读(203) 评论(0) 推荐(1)
摘要:Implement pow(x,n).1 double myPow(double x, int n) 2 {3 if(n==0) 4 return 1.0; 5 if(n<0) 6 return 1.0/pow(x,-n); 7 ret... 阅读全文
posted @ 2015-07-20 09:29 vpoet 阅读(126) 评论(0) 推荐(0)
摘要:Sort a linked list using insertion sort. 1 /** 2 * Definition for singly-linked list. 3 * struct ListNode { 4 * int val; 5 * struct ListNo... 阅读全文
posted @ 2015-07-20 09:29 vpoet 阅读(172) 评论(0) 推荐(0)
摘要:Given two sorted integer arraysnums1andnums2, mergenums2intonums1as one sorted array.Note:You may assume thatnums1has enough space (size that is great... 阅读全文
posted @ 2015-07-20 09:28 vpoet 阅读(149) 评论(0) 推荐(0)
摘要:Given an integer, write a function to determine if it is a power of two. 1 bool isPowerOfTwo(int n) 2 { 3 if(n1)10 {11 if(n%2==0)12 ... 阅读全文
posted @ 2015-07-20 09:27 vpoet 阅读(158) 评论(0) 推荐(0)
摘要:Write an algorithm to determine if a number is "happy".A happy number is a number defined by the following process: Starting with any positive integer... 阅读全文
posted @ 2015-07-20 09:23 vpoet 阅读(228) 评论(0) 推荐(0)
摘要:Given an integern, generate a square matrix filled with elements from 1 ton2in spiral order.For example,Givenn=3,You should return the following matri... 阅读全文
posted @ 2015-07-20 09:22 vpoet 阅读(274) 评论(0) 推荐(0)
摘要:Given an array and a value, remove all instances of that value in place and return the new length.The order of elements can be changed. It doesn't mat... 阅读全文
posted @ 2015-07-20 09:21 vpoet 阅读(145) 评论(0) 推荐(0)
摘要: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... 阅读全文
posted @ 2015-07-20 09:20 vpoet 阅读(182) 评论(0) 推荐(0)
摘要: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... 阅读全文
posted @ 2015-07-20 09:20 vpoet 阅读(185) 评论(0) 推荐(0)
摘要:Given a roman numeral, convert it to an integer.Input is guaranteed to be within the range from 1 to 3999. 1 class Solution { 2 public: 3 int roma... 阅读全文
posted @ 2015-07-20 09:19 vpoet 阅读(144) 评论(0) 推荐(0)
摘要: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... 阅读全文
posted @ 2015-07-20 09:18 vpoet 阅读(136) 评论(0) 推荐(0)
摘要:Given an array of integers, every element appearsthreetimes except for one. Find that single one. 1 int singleNumber(int* nums, int numsSize) 2 { 3 ... 阅读全文
posted @ 2015-07-20 09:17 vpoet 阅读(137) 评论(0) 推荐(0)