leetcode
kkkmmmjjjj
这个作者很懒,什么都没留下…
展开
-
TwoSum
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-12-16 08:38:06 · 334 阅读 · 0 评论 -
Implement strStr()
题目:Implement strStr().Returns the index of the first occurrence of needle in haystack, or -1 if needle is not part of haystack.Subscribe to see which companies asked this question思想:原创 2016-12-28 08:54:54 · 179 阅读 · 0 评论 -
LeetCode总结-初级篇(1)
想来刷题也有半月余,总共在刷题18道,均为简单题。毕竟自己代码丢了很久,水平有限。就先从简单题入手,打算2017年开始做到一天一题,一题一算,一周一结,一月一回顾,等到简单题都刷完后,再刷中等题,到时候在根据自己的水平在做规划,现在来看看这18题大概都是些什么类型的题目吧。18道题目中大致分为:数组操作、字符串操作、边界陷阱、数学题、数据结构几种。涉及的数据结构:链表:Swap原创 2016-12-31 09:04:51 · 449 阅读 · 0 评论 -
Palindrome Number
题目:Determine whether an integer is a palindrome. Do this without extra space.click to show spoilers.Some hints:Could negative integers be palindromes? (ie, -1)If you are thinking of conver原创 2016-12-21 07:36:10 · 210 阅读 · 0 评论 -
Symmetric Tree
Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center).For example, this binary tree [1,2,2,3,4,4,3] is symmetric: 1 / \ 2 2 / \ / \3 4 4 3原创 2017-01-10 08:19:50 · 404 阅读 · 0 评论 -
Construct the Rectangle
For a web developer, it is very important to know how to design a web page's size. So, given a specific rectangular web page’s area, your job by now is to design a rectangular web page, whose length L原创 2017-02-06 08:09:41 · 294 阅读 · 0 评论 -
Plus One
Given a non-negative number represented as an array of digits, plus one to the number.The digits are stored such that the most significant digit is at the head of the list.Subscribe to see原创 2017-01-01 09:21:49 · 306 阅读 · 0 评论 -
Island Perimeter
题目:You are given a map in form of a two-dimensional integer grid where 1 represents land and 0 represents water. Grid cells are connected horizontally/vertically (not diagonally). The grid is co原创 2017-01-17 07:44:01 · 250 阅读 · 0 评论 -
Sum of Two Integers
Calculate the sum of two integers a and b, but you are not allowed to use the operator + and -.Example:Given a = 1 and b = 2, return 3.Credits:Special thanks to @fujiaozhu for adding this转载 2017-01-18 07:39:51 · 256 阅读 · 0 评论 -
Find All Numbers Disappeared in an Array
Given an array of integers where 1 ≤ a[i] ≤ n (n = size of array), some elements appear twice and others appear once.Find all the elements of [1, n] inclusive that do not appear in this array.原创 2017-01-19 08:53:01 · 198 阅读 · 0 评论 -
Nim Game
You are playing the following Nim Game with your friend: There is a heap of stones on the table, each time one of you take turns to remove 1 to 3 stones. The one who removes the last stone will be the原创 2017-01-20 09:41:36 · 199 阅读 · 0 评论 -
Single Number
Given an array of integers, every element appears twice except for one. Find that single one.Note:Your algorithm should have a linear runtime complexity. Could you implement it without using ext原创 2017-01-21 14:56:44 · 212 阅读 · 0 评论 -
Number Complement
Given a positive integer, output its complement number. The complement strategy is to flip the bits of its binary representation.Note:The given integer is guaranteed to fit within the range of转载 2017-01-22 07:21:23 · 1743 阅读 · 0 评论 -
Find the Difference
Given two strings s and t which consist of only lowercase letters.String t is generated by random shuffling string s and then add one more letter at a random position.Find the letter that was转载 2017-01-23 07:58:01 · 219 阅读 · 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原创 2016-12-31 08:34:47 · 173 阅读 · 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-12-20 07:19:29 · 230 阅读 · 0 评论 -
Count and Say
题目: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原创 2016-12-30 09:20:34 · 263 阅读 · 0 评论 -
LeetCode:ZigZag Conversion
【版权声明】转载请注明出处:http://www.cnblogs.com/TenosDoIt/p/3738693.html题目链接The string "PAYPALISHIRING" is written in a zigzag pattern on a given number of rows like this: (you may want to display this转载 2016-12-17 12:32:40 · 178 阅读 · 0 评论 -
Implement int sqrt(int x).
题目:Implement int sqrt(int x).Compute and return the square root of x.思路: 我的天呀,一开始拿到这个题目完全没有感想呀,完全不知道啊,做尼玛嗨啊,第一天刷第一题就不会啊,还要把所有题目都刷干净啊,我勒个深深的草啊。网上资料:牛顿迭代法(Newton's method)又称为牛顿-拉夫逊方法(N原创 2016-12-15 08:09:53 · 669 阅读 · 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.规则:罗马数字转成整型,首先要知道罗马数字和整型的联系摘自维基百科罗马数字共有7个,即I(1)、V(5)、X(10)、L(50)、C(100原创 2016-12-22 08:11:55 · 249 阅读 · 0 评论 -
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.Subscribe to原创 2017-01-02 09:23:34 · 190 阅读 · 0 评论 -
Longest Common Prefix
题目: Longest Common PrefixWrite a function to find the longest common prefix string amongst an array of strings.题意:求所有字符串的最长公共前缀想法:每个字符串都有同样的一个公共前缀,求最长的那个,从字符串容器中取第一个字符串将其每一个字符与其后的字符串依次进行对比即可原创 2016-12-23 07:31:40 · 255 阅读 · 0 评论 -
Valid Parentheses
题目:Given a string containing just the characters '(', ')', '{', '}', '[' and ']', determine if the input string is valid.The brackets must close in the correct order, "()" and "()[]{}" are原创 2016-12-25 07:07:17 · 245 阅读 · 0 评论 -
Reverse Integer
Reverse digits of an integer.Example1: x = 123, return 321Example2: x = -123, return -321click to show spoilers.Have you thought about this?Here are some good questions to ask before c原创 2016-12-19 08:09:52 · 454 阅读 · 0 评论 -
Merge Two Sorted Lists
题目:Merge two sorted linked lists and return it as a new list. The new list should be made by splicing together the nodes of the first two lists.Subscribe to see which companies asked this原创 2016-12-26 07:34:10 · 220 阅读 · 0 评论 -
Add Binary
Given two binary strings, return their sum (also a binary string).For example,a = "11"b = "1"Return "100".Subscribe to see which companies asked this question题目:两个表示二进制字符串相加,返回原创 2017-01-04 07:56:18 · 284 阅读 · 0 评论 -
Swap Nodes in Pairs
题目: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 sh原创 2016-12-27 07:45:03 · 206 阅读 · 0 评论 -
Climbing Stairs
You are climbing a stair case. It takes n steps to reach to the top.Each time you can either climb 1 or 2 steps. In how many distinct ways can you climb to the top?Note: Given n will be a posi原创 2017-01-05 08:10:02 · 458 阅读 · 0 评论 -
Remove Duplicates from Sorted Array
题目:Remove Duplicates from Sorted ArrayGiven 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 a原创 2016-12-28 07:58:02 · 197 阅读 · 0 评论 -
Remove Element
题目:Given an array and a value, remove all instances of that value in place and return the new length.Do not allocate extra space for another array, you must do this in place with constant memo原创 2016-12-28 08:24:45 · 189 阅读 · 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 ad原创 2017-01-06 08:01:59 · 199 阅读 · 0 评论 -
Valid Sudoku
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 filled转载 2016-12-29 08:24:35 · 222 阅读 · 0 评论 -
Add Digits
Given a non-negative integer num, repeatedly add all its digits until the result has only one digit.For example:Given num = 38, the process is like: 3 + 8 = 11, 1 + 1 = 2. Since 2 has only o原创 2017-01-24 08:39:39 · 217 阅读 · 0 评论