摘要: 148. Sort List 题目:Sort a linked list in O(n log n) time using constant space complexity. 题意:排序链表 思路I:merge sort 复杂度分析:时间复杂度O(nlgn),空间复杂度O(1) 1 /** 2 * 阅读全文
posted @ 2017-12-11 14:59 揪萌striving 阅读(250) 评论(0) 推荐(0) 编辑
摘要: JDBC(java database connectivity) java数据库连接,就是用Java语言来操作数据库。原来我们操作数据库是在控制台中通过sql语句来操作数据库,而Jdbc是用Java语言来向数据库发送sql语句来操作数据库。 JDBC操作数据库的四个流程已经在代码中标注。 阅读全文
posted @ 2017-05-02 15:48 揪萌striving 阅读(149) 评论(0) 推荐(0) 编辑
摘要: 随时补充 Remove Substrings Given a string s and a set of n substrings. You are supposed to remove every instance of those n substrings from s so that s is 阅读全文
posted @ 2017-04-25 20:11 揪萌striving 阅读(427) 评论(0) 推荐(0) 编辑
摘要: Advanced Data Structure -- Union Find Number of Islands Given a boolean 2D matrix, 0 is represented as the sea, 1 is represented as the island. If two 阅读全文
posted @ 2017-03-15 20:01 揪萌striving 阅读(911) 评论(0) 推荐(0) 编辑
摘要: 310. Minimum Height Trees For a undirected graph with tree characteristics, we can choose any node as the root. The result graph is then a rooted tree 阅读全文
posted @ 2017-03-07 15:24 揪萌striving 阅读(455) 评论(0) 推荐(0) 编辑
摘要: 1. Maximum Subtree 思路:Divide Conquer,保存全局sum和node。 1 public class Solution { 2 int maxSum = Integer.MIN_VALUE; 3 TreeNode node = null; 4 /** 5 * @para 阅读全文
posted @ 2017-03-05 14:18 揪萌striving 阅读(274) 评论(0) 推荐(0) 编辑
摘要: 1.PriorityQueue的方法iterator()中提供的迭代器并不保证以有序的方式遍历优先级队列中的元素,因此不能使用此迭代器依次遍历PriorityQueue中的队头元素。 2. hash函数避免冲突的经验值取大质数(如果capacity比较大的话)。比如如下的冲突避免hash funct 阅读全文
posted @ 2017-02-26 20:34 揪萌striving 阅读(157) 评论(0) 推荐(0) 编辑
摘要: 1. Linked List Cycle(判断链表是否有环) 思路:设置slow和fast两个指针,初始化为head和head.next。遇到slow == fast说明有环,遇到fast == null || fast.next == null说明无环。模版程序如下。 1 public class 阅读全文
posted @ 2017-02-17 15:55 揪萌striving 阅读(383) 评论(0) 推荐(0) 编辑
摘要: 对于一个给定的 source 字符串和一个 target 字符串,你应该在 source 字符串中找出 target 字符串出现的第一个位置(从0开始)。如果不存在,则返回 -1。 基本:两重for循环,时间复杂度O(n^2)。 1 class Solution { 2 /** 3 * Return 阅读全文
posted @ 2017-01-15 18:41 揪萌striving 阅读(197) 评论(0) 推荐(0) 编辑
摘要: 面试题3 -- 搜索二维矩阵 写出一个高效的算法来搜索 m × n矩阵中的值。 这个矩阵具有以下特性: 1. 每行中的整数从左到右是排序的。 2. 每行的第一个数大于上一行的最后一个整数。 思路:二分位置0 ~ n * m - 1 1 public class Solution { 2 /** 3 阅读全文
posted @ 2017-01-15 09:59 揪萌striving 阅读(308) 评论(0) 推荐(0) 编辑