自定义博客皮肤VIP专享

*博客头图:

格式为PNG、JPG,宽度*高度大于1920*100像素,不超过2MB,主视觉建议放在右侧,请参照线上博客头图

请上传大于1920*100像素的图片!

博客底图:

图片格式为PNG、JPG,不超过1MB,可上下左右平铺至整个背景

栏目图:

图片格式为PNG、JPG,图片宽度*高度为300*38像素,不超过0.5MB

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+
  • 博客(26)
  • 收藏
  • 关注

原创 Contains Duplicate II

题目: Given an array of integers and an integer k, find out whether there there are two distinct indices i and j in the array such that nums[i] = nums[j] and the difference between iand j is at

2015-06-30 10:24:49 210

原创 Convert Sorted List to Binary Search Tree

题目: Given a singly linked list where elements are sorted in ascending order, convert it to a height balanced BST. 解题思路: 具体思路即为,每次查找到中间的节点,将其作为树的根节点,以该点切分,其左侧以及右侧皆采用此方法,最终即构建出来所需的树。边界条件需要多加注意。此题思路

2015-06-20 16:27:25 299

原创 Partition List

题目: 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 original relative order of the nodes i

2015-06-19 09:21:02 208

原创 Remove Linked List Elements

题目: Remove all elements from a linked list of integers that have value val. Example Given: 1 --> 2 --> 6 --> 3 --> 4 --> 5 --> 6, val = 6 Return: 1 --> 2 --> 3 --> 4 --> 5 代码: # Definition

2015-06-18 14:20:42 200

原创 Remove Duplicates from Sorted List II

题目: Given a sorted linked list, delete all nodes that have duplicate numbers, leaving only distinct numbers from the original list. For example, Given 1->2->3->3->4->4->5, return 1->2->5. Gi

2015-06-18 11:24:18 251

原创 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. 代码: 此题简单,但未一次通过

2015-06-18 11:07:46 235

原创 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 removing the second node from the

2015-06-18 10:55:41 206

原创 Merge k Sorted Lists

题目: Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity. 解题思路: (1)、二分法(accept) 此法比较巧妙,当时没有想起用这个方法。复杂度为O(nlgn) # Definition for singly-linked list

2015-06-18 10:01:32 199

原创 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. 解题思路: # Definition for singly-linked list. # c

2015-06-17 16:02:24 222

原创 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 left-out nodes in the end should remain

2015-06-17 15:51:16 225

原创 Reverse Linked List II

题目: Reverse a linked list from position m to n. Do it in-place and in one-pass. For example: Given 1->2->3->4->5->NULL, m = 2 and n = 4, return 1->4->3->2->5->NULL. Note: Given m, n 

2015-06-14 09:48:09 203

原创 Reverse Linked List

题目: Reverse a singly linked list. Hint: A linked list can be reversed either iteratively or recursively. Could you implement both? 解题思路: (1)、迭代版 分析以上代码,一开始时我是将head=head.next放在一

2015-06-12 15:39:55 162

原创 Rotate List

题目: Given a list, rotate the list to the right by k places, where k is non-negative. For example: Given 1->2->3->4->5->NULL and k = 2, return 4->5->1->2->3->NULL. 解题思路: 我在解此题时,遇到的最大问题是没能完全

2015-06-12 11:08:00 227

原创 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

2015-06-11 15:51:02 255

原创 Subsets II

题目: Given a collection of integers that might contain duplicates, nums, return all possible subsets. Note: Elements in a subset must be in non-descending order. The solution set must not contain

2015-06-10 21:46:20 220

原创 Subsets

题目: Given a set of distinct integers, nums, return all possible subsets. Note: Elements in a subset must be in non-descending order. The solution set must not contain duplicate subsets. For e

2015-06-10 21:25:31 211

原创 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. 解题思路:

2015-06-09 17:20:12 212

原创 Palindrome Number

题目: Determine whether an integer is a palindrome. Do this without extra space. 解题思路:            此题有两种解法,一种可以用递归方式,很容易理解。另一张就是迭代方式。由于此题要求不能有额外的空间开销。故使用迭代,但在此说明一下          (1)、 递归方式 class Solutio

2015-06-06 15:06:39 197

原创 Reverse Integer

题目:        Reverse digits of an integer. Example1: x = 123, return 321 Example2: x = -123, return -321 解题思路: 此题极为简单,但有一个小陷阱。附链接https://leetcode.com/discuss/28079/one-python-test-case-i

2015-06-05 20:15:27 208

原创 最长公共子序列问题(LCS)

1、递归版本              对于序列A[0,n]和B[0,m],LCS(A,B)无非三种情况             (0)若n=-1或m=-1,则取做空序列(“”)                                            //递归基             (1)若A[n]='X'=B[m],则取做:LCS(A[0,n),B[0,m))+‘X’  

2015-06-05 15:52:34 252

原创 Longest Palindromic Substring

题目:        Given a string S, find the longest palindromic substring in S. You may assume that the maximum length of S is 1000, and there exists one unique longest palindromic substring. 解题思路:

2015-06-05 10:04:13 230

原创 Median of Two Sorted Arrays

题目:          There are two sorted arrays nums1 and nums2 of size m and n respectively. Find the median of the two sorted arrays. The overall run time complexity should be O(log (m+n)). 解题思路:  

2015-06-04 09:37:02 232

原创 Longest Substring Without Repeating Characters

题目: Given a string, find the length of the longest substring without repeating characters. For example, the longest substring without repeating letters for "abcabcbb" is "abc", which the length is

2015-06-04 08:35:19 237

转载 n次幂求法

《数据结构与算法分析》mark.Allen.weiss中提供的分治算法可以用于解决任意情形的指数运算(或者称为幂运算),是一个典型算法。 C/C++ code ? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 bool isE

2015-06-03 21:41:44 543

原创 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 digit. Add the two numbers and return it

2015-06-02 16:06:55 243

原创 3Sum Closest

题目: Given an array S of n integers, find three integers in S such that the sum is closest to a given number, target. Return the sum of the three integers. You may assume that each input would hav

2015-06-02 11:04:32 227

空空如也

空空如也

TA创建的收藏夹 TA关注的收藏夹

TA关注的人

提示
确定要删除当前文章?
取消 删除