LeeCode
poetliu
这个作者很懒,什么都没留下…
展开
-
LeeCode--Two Sum
LeeCode上的题目原创 2014-10-23 14:19:45 · 839 阅读 · 0 评论 -
LeeCode-Remove Element
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 matter what you leave beyond the new length.c原创 2016-04-25 18:59:15 · 382 阅读 · 0 评论 -
LeeCode-Spiral Matrix II
Given an integer n, generate a square matrix filled with elements from 1 to n2 in spiral order.For example,Given n = 3,You should return the following matrix:[ [ 1, 2, 3 ], [ 8, 9, 4 ],原创 2016-04-25 19:00:08 · 426 阅读 · 0 评论 -
LeeCode-Happy Number
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, replace the number by the sum of the squares原创 2016-04-25 19:01:21 · 406 阅读 · 0 评论 -
LeeCode-Power of Two
Given an integer, write a function to determine if it is a power of two.bool isPowerOfTwo(int n){ if(n<=0) return false; if(n==1) return true; bool judge=false;原创 2016-04-25 19:02:08 · 360 阅读 · 0 评论 -
LeeCode-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 a原创 2016-04-25 19:03:23 · 358 阅读 · 0 评论 -
LeeCode-Insertion Sort List
Sort a linked list using insertion sort./** * Definition for singly-linked list. * struct ListNode { * int val; * struct ListNode *next; * }; */struct ListNode* insertionSortList(原创 2016-04-25 19:04:08 · 384 阅读 · 0 评论 -
LeeCode-Remove Linked List Elements
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 --> 5/** * Definition原创 2016-04-26 20:44:58 · 492 阅读 · 0 评论 -
LeeCode-Pow(x, n)
Implement pow(x, n).double myPow(double x, int n) { if(n==0) return 1.0; if(n<0) return 1.0/pow(x,-n); return x*pow(x,n-1); }原创 2016-04-26 20:44:03 · 587 阅读 · 0 评论 -
LeeCode-Sqrt(x)Implement int sqrt(int x). Compute and return the square root of x.
Implement int sqrt(int x).Compute and return the square root of x.int mySqrt(int x) { if(x==1) return 1;/* for(int i=2;i<=x/2;i++) { if(x=i*i) {原创 2016-04-26 20:46:29 · 1418 阅读 · 0 评论 -
LeeCode-Rotate Array
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-04-26 20:47:18 · 481 阅读 · 0 评论 -
LeeCode-Two Sum
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 numbers such that they add up to the target, whe原创 2016-04-26 20:48:16 · 613 阅读 · 0 评论 -
LeeCode(Database)-Combine Two Tables
Table: Person+-------------+---------+| Column Name | Type |+-------------+---------+| PersonId | int || FirstName | varchar || LastName | varchar |+-------------+---------+Per原创 2016-04-26 20:50:16 · 491 阅读 · 0 评论 -
LeeCode(Database)-Employees Earning More Than Their Managers
The Employee table holds all employees including their managers. Every employee has an Id, and there is also a column for the manager Id.+----+-------+--------+-----------+| Id | Name | Salary |原创 2016-04-26 20:51:08 · 527 阅读 · 0 评论 -
LeeCode(Database)-Duplicate Emails
Write a SQL query to find all duplicate emails in a table named Person.+----+---------+| Id | Email |+----+---------+| 1 | a@b.com || 2 | c@d.com || 3 | a@b.com |+----+---------+For原创 2016-04-26 20:52:02 · 541 阅读 · 0 评论 -
LeeCode-Sort Colors
Given an array with n objects colored red, white or blue, sort them so that objects of the same color are adjacent, with the colors in the order red, white and blue.Here, we will use the integer原创 2016-04-25 18:58:06 · 431 阅读 · 0 评论 -
LeeCode-Swap Nodes in Pairs
Given a linked list, swap every two adjacent nodes and return its head.For example,Given 1->2->3->4, you should return the list as 2->1->4->3.Your algorithm should use only constant space. Y原创 2016-04-25 18:57:08 · 371 阅读 · 0 评论 -
LeeCode-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原创 2016-04-25 18:40:54 · 370 阅读 · 0 评论 -
LeeCode-Same Tree
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 and the nodes have the same value./**原创 2016-04-25 18:44:03 · 415 阅读 · 0 评论 -
LeeCode-Delete Node in a Linked List
Write a function to delete a node (except the tail) in a singly linked list, given only access to that node.Supposed the linked list is 1 -> 2 -> 3 -> 4 and you are given the third node with value原创 2016-04-25 18:44:56 · 349 阅读 · 0 评论 -
LeeCode-Number of 1 Bits
Write a function that takes an unsigned integer and returns the number of ’1' bits it has For example, the 32-bit integer ’11' has binary representation 00000000000000000000000000001011,so the functio原创 2016-04-25 18:48:48 · 303 阅读 · 0 评论 -
LeeCode-Linked List Cycle
Given a linked list, determine if it has a cycle in it./** * Definition for singly-linked list. * struct ListNode { * int val; * struct ListNode *next; * }; */bool hasCycle(struct Lis原创 2016-04-25 18:49:38 · 375 阅读 · 0 评论 -
LeeCode-Contains Duplicate
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 array, and it should return false if every element原创 2016-04-25 18:50:40 · 318 阅读 · 0 评论 -
LeeCode-Invert Binary Tree
Invert a binary tree. 4 / \ 2 7 / \ / \1 3 6 9to 4 / \ 7 2 / \ / \9 6 3 1/** * Definition for a binary tree node. * public class TreeNode { *原创 2016-04-25 18:51:44 · 355 阅读 · 0 评论 -
LeeCode-Majority Element
Given an array of size n, find the majority element. The majority element is the element that appears more than ⌊ n/2 ⌋ times.You may assume that the array is non-empty and the majority element原创 2016-04-25 18:52:50 · 358 阅读 · 0 评论 -
LeeCode-Single Number II
Given an array of integers, every element appears three times except for one. Find that single one.int singleNumber(int* nums, int numsSize) { if(numsSize==1) return nums[0]; int原创 2016-04-25 18:53:43 · 374 阅读 · 0 评论 -
LeeCode-Remove Duplicates from Sorted List
Given a sorted linked list, delete all duplicates such that each element appear only once.For example,Given 1->1->2, return 1->2.Given 1->1->2->3->3, return 1->2->3./** * Definition for s原创 2016-04-25 18:55:21 · 411 阅读 · 0 评论 -
LeeCode-Roman to Integer
Given a roman numeral, convert it to an integer.Input is guaranteed to be within the range from 1 to 3999.class Solution {public: int romanToInt(string s) { int length = s.length(原创 2016-04-25 18:56:15 · 382 阅读 · 0 评论 -
LeeCode(Database)-Customers Who Never Order
Suppose that a website contains two tables, the Customers table and the Orders table. Write a SQL query to find all customers who never order anything.Table: Customers.+----+-------+| Id | Na原创 2016-04-26 20:52:52 · 511 阅读 · 0 评论