2016年4月26日

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

posted @ 2016-04-26 21:46 Sheryl Wang 阅读(177) 评论(0) 推荐(0) 编辑

Longest Common Prefix

摘要: Write a function to find the longest common prefix string amongst an array of strings. 这是一道字符串的简单题.思路也非常简单,基本都是brute force的解法.具体解法分为:按列扫和按行扫两种. 按列扫,是每 阅读全文

posted @ 2016-04-26 10:23 Sheryl Wang 阅读(160) 评论(0) 推荐(0) 编辑

2016年4月25日

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 @ 2016-04-25 14:55 Sheryl Wang 阅读(119) 评论(0) 推荐(0) 编辑

2016年4月24日

Merge k Sorted Lists

摘要: Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity. 这是一道hard的题目,但是其实思路并不复杂,做起来也比较有趣。做完Merge Two Sorted 阅读全文

posted @ 2016-04-24 16:36 Sheryl Wang 阅读(155) 评论(0) 推荐(0) 编辑

Kth Largest Element in an Array

摘要: 利用最小堆解决,代码如下: 另外一个是使用快排的partition的方法(可见剑指offer167页),寻找index为k-1的pivot ,原理是 一次partition之后,pivot左边的数都小于等于pivot,右边的数都大于等于pivot,所以pivot左边加pivot形成index个数组中 阅读全文

posted @ 2016-04-24 12:00 Sheryl Wang 阅读(189) 评论(0) 推荐(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. 这题与Add T 阅读全文

posted @ 2016-04-24 11:34 Sheryl Wang 阅读(137) 评论(0) 推荐(0) 编辑

2016年4月23日

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 @ 2016-04-23 20:44 Sheryl Wang 阅读(156) 评论(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 @ 2016-04-23 17:25 Sheryl Wang 阅读(242) 评论(0) 推荐(0) 编辑

2016年4月18日

Longest Substring Without Repeating Characters

摘要: 题意为给出一个字符串,找出其中没有重复字符的最长子序列的长度。brute force的复杂度为O(n^3).依次查找每个子字符串是否含有重复字符,并比较长度。开始看到题目,想用DP解决,在已有目前最长子序列的情况下,比较把当前字符串放入和不放入,哪个子序列长度会更大,但是这种解法的复杂度为O(n^2 阅读全文

posted @ 2016-04-18 23:07 Sheryl Wang 阅读(143) 评论(0) 推荐(0) 编辑

Construct Binary Tree from Inorder and Postorder Traversal

摘要: 思路和依据前序遍历和中序遍历重建树的思路一样,复杂度也一致,代码如下: 阅读全文

posted @ 2016-04-18 20:14 Sheryl Wang 阅读(145) 评论(0) 推荐(0) 编辑

导航