随笔分类 -  leetcode

N-Queens I&&II
摘要:The n-queens puzzle is the problem of placing n queens on an n×n chessboard such that no two queens attack each other. Given an integer n, return all 阅读全文

posted @ 2014-10-06 15:26 bug睡的略爽 阅读(188) 评论(0) 推荐(0)

Anagrams
摘要:Given an array of strings, return all groups of strings that are anagrams. Note: All inputs will be in lower-case. For example: Input: ["tea","and","a 阅读全文

posted @ 2014-10-06 10:15 bug睡的略爽 阅读(119) 评论(0) 推荐(0)

Multiply Strings
摘要:Given two numbers represented as strings, return multiplication of the numbers as a string. Note: The numbers can be arbitrarily large and are non-neg 阅读全文

posted @ 2014-10-05 17:15 bug睡的略爽 阅读(133) 评论(0) 推荐(0)

Combination Sum I&&II
摘要:Given a set of candidate numbers (C) and a target number (T), find all unique combinations in C where the candidate numbers sums to T. The same repeat 阅读全文

posted @ 2014-10-05 15:23 bug睡的略爽 阅读(143) 评论(0) 推荐(0)

Search for a Range
摘要:Given a sorted array of integers, find the starting and ending position of a given target value. Your algorithm's runtime complexity must be in the or 阅读全文

posted @ 2014-10-05 14:53 bug睡的略爽 阅读(165) 评论(0) 推荐(0)

Divide Two Integers
摘要:Divide two integers without using multiplication, division and mod operator. 方法一:暴力破解,不断用被除数减去除数,直至出现负数停止,铁定超时。 方法二:对方法一的改进,每次寻找 满足2k-1 * 除数 <= 被除数 < 阅读全文

posted @ 2014-10-01 23:24 bug睡的略爽 阅读(140) 评论(0) 推荐(0)

Remove Duplicates from Sorted Array I&&II
摘要: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 fo 阅读全文

posted @ 2014-10-01 17:06 bug睡的略爽 阅读(99) 评论(0) 推荐(0)

Reverse Nodes in k-Group
摘要:Given a linked list, reverse the nodes of a linked list k at a time and return its modified list. If the number of nodes is not a multiple of k then l 阅读全文

posted @ 2014-10-01 16:57 bug睡的略爽 阅读(184) 评论(0) 推荐(0)

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 a 阅读全文

posted @ 2014-10-01 11:38 bug睡的略爽 阅读(161) 评论(0) 推荐(0)

Merge k Sorted Lists
摘要:Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity. 方法一:暴力破解,1和2合并,合并后再和3合并,合并后再和4合并。。。如此下去一直将所有链表节点全部合 阅读全文

posted @ 2014-10-01 11:10 bug睡的略爽 阅读(164) 评论(0) 推荐(0)

Remove Nth Node From End of List
摘要: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 rem 阅读全文

posted @ 2014-09-16 09:43 bug睡的略爽 阅读(172) 评论(0) 推荐(0)

Letter Combinations of a Phone Number
摘要:Given a digit string, return all possible letter combinations that the number could represent. A mapping of digit to letters (just like on the telepho 阅读全文

posted @ 2014-09-15 22:55 bug睡的略爽 阅读(197) 评论(0) 推荐(0)

Integer to Roman
摘要:Given an integer, convert it to a roman numeral. Input is guaranteed to be within the range from 1 to 3999. 普及一下罗马计数法 The base I - 1 V - 5 X - 10 L - 阅读全文

posted @ 2014-09-15 22:23 bug睡的略爽 阅读(171) 评论(0) 推荐(0)

Regular Expression Matching
摘要:Implement regular expression matching with support for '.' and '*'. '.' Matches any single character. '*' Matches zero or more of the preceding elemen 阅读全文

posted @ 2014-09-15 20:45 bug睡的略爽 阅读(195) 评论(0) 推荐(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 阅读全文

posted @ 2014-09-15 15:27 bug睡的略爽 阅读(147) 评论(0) 推荐(0)

Add Two Numbers
摘要: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 阅读全文

posted @ 2014-09-15 11:11 bug睡的略爽 阅读(174) 评论(0) 推荐(0)

Pow(x, n)
摘要:Implement pow(x, n). 这题主要考察分治法,这样效率就可达到O(logn) 需要注意的是:n>0时 n为偶数时 xn = xn/2 * xn/2,n为奇数时 xn = x(n-1)/2 * x(n-1)/2 * x n=0时 ,xn = 1 n<0时 xn = 1 / x-n 代码 阅读全文

posted @ 2014-09-07 22:27 bug睡的略爽 阅读(159) 评论(0) 推荐(0)

Implement strStr()
摘要:Implement strStr(). Returns a pointer to the first occurrence of needle in haystack, or null if needle is not part of haystack. 方法一:暴力破解,O(mn),超时,写了这段 阅读全文

posted @ 2014-09-07 21:32 bug睡的略爽 阅读(167) 评论(0) 推荐(0)

Edit Distance
摘要:Given two words word1 and word2, find the minimum number of steps required to convert word1 to word2. (each operation is counted as 1 step.) You have 阅读全文

posted @ 2014-09-06 21:05 bug睡的略爽 阅读(138) 评论(0) 推荐(0)

Sqrt(x)
摘要:Implement int sqrt(int x). Compute and return the square root of x. 传说中的牛顿法,请查看百度百科 某人说我偷懒,那我就决定还是翻些资料出来比较好。。。 牛顿法主要用于两方面,一是求方程根,二是最优化处理。 求方程根的原理是利用泰勒 阅读全文

posted @ 2014-09-06 20:30 bug睡的略爽 阅读(203) 评论(0) 推荐(0)

导航