- 博客(324)
- 收藏
- 关注
原创 Boyer Moore算法分析总结
简介 在之前的文章里,对于字符串的搜索算法,我曾经讨论过KMP算法的思路和实现。 KMP算法的实现思路是基于模式串里面的的前缀和后缀匹配,这种算法的效率已经足够快了。没想到的是,这里我们要讨论的Boyer Moore算法效率更加惊人。 思路分析 在之前的算法里,我们是通过从模式串的开头到结尾这么一个个的去和目标串比较,这种方式在碰到匹配的元素时则继续比较下一个,在没...
2017-03-31 18:42:27
573
mybatis学习总结:mybatis和spring, spring boot的集成
简介 在前面的讨论里已经提到了mybatis的各种配置和操作。从原生的使用角度来看,其实还是有点繁琐的,因为要配置数据源、指定配置文件,设定mapper文件以及接口。在实际的应用中,单纯使用mybatis的机会并不多,它更多的是和spring结合起来用。这里,我们就结合具体的示例讨论详细的配置过程。 和spring的集成 mybatis和spring的集成需要额外加入一些依赖...
2017-03-04 18:07:21
456
原创 mybatis学习总结:annotation与xml结合示例
简介 在之前的文章里讨论过mybatis纯xml或者annotation的开发。同时,也讨论了针对不同对象关系情况下的实现细节。在实际的开发应用中,我们会发现,有时候单纯的使用某一种方式来开发的话并不一定有最佳的效率。比如说当我们使用纯xml的时候,会发现里面有很多比较繁琐的配置,而且因为很多sql语句因为是写在xml配置文件里,一个是容易出错,另外对于一些特殊符号还要做一些处理,这样就...
2017-02-25 21:09:15
731
原创 mybatis学习总结:对象关系映射的xml配置实现
简介 在之前的文章里已经讨论过mybatis的基本配置和应用,但是在实际应用中,我们需要支持更加复杂的操作,比如对多个表之间数据的连接访问等。这里就牵涉到数据关系建模里的各种关系映射。比如一对一映射,一对多映射等。这里对这几种情况的实现做一个讨论。 数据库表结构定义 在讨论具体的实现代码之前,我们先定义一系列的数据库表。它们有的是一对一的关系,有的是一对多的关系。这些表格的...
2017-02-19 23:03:09
613
原创 mybatis学习总结:annotation示例改进
简介 在前一篇文章里我们已经讨论了一个简单的基于xml配置文件运行mybatis的示例。实际上,要完成上述的功能,mybatis里还提供了一种基于annotation的实现方式。对于有些不喜欢繁琐的xml配置文件的人来说,这种方式因为是添加标注到代码里,并不会带来实现上的侵入。总的来说,这种方式会显得稍微简洁一点。 项目修改 结合前面那个项目来看,我们通过xml配置的重点在...
2017-01-24 09:06:58
344
原创 mybatis学习总结:基础示例
简介 mybatis是一个比较流行的ORM框架,在很多应用里都有牵涉到。它本身提供对原生sql语句的支持,同时可以让使用者采用更加细粒度的方式来设置对象和数据的映射关系。本文通过一个简单的示例来熟悉mybatis工程的配置和api应用。 工程示例 这个示例采用mysql数据库,结合mybatis的xml配置文件进行设置。 创建数据库 首先,我们创建一个数据...
2017-01-21 23:30:57
193
原创 Trie树的分析和理解
简介 在使用一些搜索引擎去搜一些东西的时候,我们经常会碰到一个有意思的事情。有时候我们在搜索框输入一部分内容的时候,会发现搜索框会显示一个下拉的列表,里面有一些以前面输入的内容为开头的一系列搜索字段。比如当输入search的时候,搜索框会显示如下的内容: 如图所示,这里显示一个比较神奇的东西,网站居然可以给我们有一个自动补全的提示,这样可以省略了一些手动的输入。 那么,是什么可...
2017-01-05 23:22:06
639
原创 gradle学习总结
简介 Java的自动化构建工具比较多,从最开始的ant,到maven以及现在的gradle。他们的灵活性和功能越来越强大。相对前面的工具来说,gradle使用专门的编程groovy来描述项目构建过程中的一些任务。由于有编程语言的灵活性,它的表达能力更加强,结合一些强大的插件支持,我们可以使用少量的代码和配置来达到项目构建的目的。这里针对一些常见的问题做一个总结。 安装 ...
2016-12-18 21:01:13
313
原创 String sort的几种方法
简介 在之前的一些排序算法中,主要是对一些数值的类型比较的比较多一点。而对于字符串类型来说,它有一些特殊的性质。如果按照传统的排序方法,对于字符串的比较性能其实还取决于字符串的长度以及相似程度。实际上,对于一些字符集的取值在一个比较小的范围内的情况,我们可以有一些比较高效率的算法。这里针对这些特殊的情况进行讨论。 假设给定的排序集合里元素,也就是每个字符都是在一个比较有限的范围里,...
2016-10-16 23:07:32
4790
原创 Shortest path in complement graph
问题描述 Shortest path in complement graph.:Given a graph G, design an algorithm to find the shortest path (number of edges) between s and every other vertex in the complement graph G'. The compl...
2016-09-01 23:26:06
328
原创 Diameter of a tree
简介 在之前的文章里我讨论过计算图里最短路径的几种方法,一个是Dijkstra's algorithm,一个是Bellman-Ford Algorithm。它们都是针对一个比较通用形式的图来进行计算处理的。在实际的应用中,有些比较特殊的图,在计算它们的最短路径的应用中往往还有一些更加简单的方法。 问题描述 Given a graph that is a tree (con...
2016-08-30 23:24:41
588
原创 Bellman-Ford Algorithm
简介 我在之前的文章里有对Dijkstra's Algorithm进行了思路的分析和讨论,但是也提到了一点,就是这个算法它有一点限制,要求图里面所有的边的权值都是非负的。因为如果有权值为负数的边,就打破了原来算法里每次取得的当前最小值是全局最优值这个假定了。那么在图里面真有权值为负数的边时,甚至在某些情况下存在有加权值为负数的环时,我们该怎么来计算单点源的最短路径呢? 这里,我们将...
2016-08-25 23:03:07
374
原创 Dijkstra's algorithm再理解
简介Dijkstra's algorithm是一个求图中单点到其他所有点最短距离的算法。我在之前的一篇文章里也有过一些讨论。只是那篇文章写得比较仓促,对于该算法的思想和推导理解得也并不深刻。经过一些时间的思考,这里想对该算法的思想做一个进一步的阐述,并对一些和它相关的问题进行比较讨论。 算法描述分析 对于这个算法来说,它有这么一个前提。在一个连通的图中(可以是有向图或者无向图...
2016-08-11 23:17:29
8877
1
原创 All paths in a graph
问题描述 给定一个图中间两个节点,我们需要返回这两个节点之间所有的simple path。什么是simple path呢?就是图中间不包含有重复节点的路径。 问题分析 对于这个问题,我们比较容易想到一些和其他问题近似的地方。比如说给定两个节点要判断它们是否连通。而且在连通的时候我们可以找到一条这两个节点之间的路径。对于这个相对简化的问题来说,我们可以通过图的某种遍历方式,每...
2016-07-26 22:16:02
201
原创 Deletion order
问题描述 给定一个连通的图,确定一个删除节点的顺序,使得每次删除节点之后图的剩余部分依然是连通的。要求算法的时间复杂度是O(V + E)。 分析 这个问题粗看起来比较复杂。因为对于一个图来说,假设我们要删除一个节点,那么它所对应的边都要被删掉。光去遍历所有的节点找到所有包含某个要删除节点的边都要费很大的劲。所以不能单纯的用一个个查找然后删除的方法。 我们来看这个问题的...
2016-07-25 23:18:27
190
原创 图bridge计算的讨论
简介 最近在学习一些图相关的算法时碰到一个比较有意思的问题。就是关于图中间桥的问题。在图中,一般的边是用于连接两个节点的。如果结合图的连通性来考虑,假设一个边连着图的两个部分,如果我们将这个边去掉,那么将使得图变成两个分割开的部分。那么,这个时候我们称这个边是桥。 那么,对于一个图来说,我们能否找到一些这样的桥呢? 分析 在找到具体的规律之前,我们先看一个图的示例:...
2016-07-14 23:53:21
654
原创 leetcode:Binary Tree Upside Down
问题描述Given a binary tree where all the right nodes are either leaf nodes with a sibling (a left node that shares the same parent node) or empty, flip it upside down and turn it into a tree where th...
2016-07-10 15:36:22
172
leetcode: Find Minimum in Rotated Sorted Array II
问题描述:Follow up for "Find Minimum in Rotated Sorted Array":What if duplicates are allowed?Would this affect the run-time complexity? How and why?Suppose a sorted array is rotated at some piv...
2016-07-10 09:26:31
152
leetcode: Find Minimum in Rotated Sorted Array
问题描述:Suppose a sorted array is rotated at some pivot unknown to you beforehand.(i.e., 0 1 2 4 5 6 7 might become 4 5 6 7 0 1 2).Find the minimum element.You may assume no duplicate exists in...
2016-07-10 08:37:25
164
leetcode: Maximum Product Subarray
问题描述:Find the contiguous subarray within an array (containing at least one number) which has the largest product.For example, given the array [2,3,-2,4],the contiguous subarray [2,3] has the larg...
2016-07-09 20:39:49
179
leetcode: Reverse Words in a String
问题描述:Given an input string, reverse the string word by word.For example,Given s = "the sky is blue",return "blue is sky the".Update (2015-02-12):For C programmers: Try to solve it in-place in O...
2016-07-09 20:19:40
145
leetcode: Evaluate Reverse Polish Notation
问题描述:Evaluate the value of an arithmetic expression in Reverse Polish Notation.Valid operators are +, -, *, /. Each operand may be an integer or another expression.Some examples: ...
2016-07-09 20:03:32
131
原创 leetcode: Max Points on a Line
问题描述:Given n points on a 2D plane, find the maximum number of points that lie on the same straight line.原问题链接:https://leetcode.com/problems/max-points-on-a-line/ 问题分析 给定一个平面上若干个点来说,要计算有多少...
2016-07-09 19:47:00
157
原创 leetcode: Sort List
问题描述:Sort a linked list using insertion sort.原问题链接:https://leetcode.com/problems/sort-list/ 问题分析 有时候,往往是一些看似简单的问题描述 ,其解决方法越麻烦。这里问题描述确实简单,对于一个链表来说,我们需要寻找一种时间复杂度为O(NlogN)的排序法。对于数组来说,要找到这种时间...
2016-07-08 20:15:02
89
原创 leetcode: Insertion Sort List
问题描述:Sort a linked list using insertion sort.原问题链接:https://leetcode.com/problems/insertion-sort-list/ 问题分析 这里因为是针对链表进行插入排序,其过程和普通数组的插入排序有点不一样。相对来说因为没有直接的索引访问,它要复杂不少。在针对链表的插入排序实现前,我们先看看基于数...
2016-07-08 20:03:08
142
leetcode: LRU Cache
问题描述:Design and implement a data structure for Least Recently Used (LRU) cache. It should support the following operations: get and set.get(key) - Get the value (will always be positive) of the k...
2016-07-07 22:50:25
88
原创 leetcode: Binary Tree Postorder Traversal
问题描述:Given a binary tree, return the postorder traversal of its nodes' values.For example:Given binary tree {1,#,2,3}, 1 \ 2 / 3 return [3,2,1].Note: Recursive so...
2016-07-07 22:33:32
85
leetcode: Binary Tree Preorder Traversal
问题描述:Given a binary tree, return the preorder traversal of its nodes' values.For example:Given binary tree {1,#,2,3}, 1 \ 2 / 3 return [1,2,3].Note: Recursive solu...
2016-07-07 22:08:01
112
原创 leetcode: Reorder List
问题描述:Given a singly linked list L: L0→L1→…→Ln-1→Ln,reorder it to: L0→Ln→L1→Ln-1→L2→Ln-2→…You must do this in-place without altering the nodes' values.For example,Given {1,2,3,4}, reorder it to...
2016-07-07 21:40:29
114
原创 leetcode: Linked List Cycle II
问题描述:Given a linked list, return the node where the cycle begins. If there is no cycle, return null.Note: Do not modify the linked list.Follow up:Can you solve it without using extra space?原...
2016-07-07 08:10:31
103
leetcode: Linked List Cycle
问题描述:Given a linked list, determine if it has a cycle in it.Follow up:Can you solve it without using extra space?原问题链接:https://leetcode.com/problems/linked-list-cycle/ 问题分析 这是一个比较老的问题了。要...
2016-07-06 22:48:19
124
原创 leetcode: Word Break II
问题描述:Given a string s and a dictionary of words dict, add spaces in s to construct a sentence where each word is a valid dictionary word.Return all such possible sentences.For example, givens ...
2016-07-06 22:41:40
111
leetcode: Word Break
问题描述:Given a string s and a dictionary of words dict, determine if s can be segmented into a space-separated sequence of one or more dictionary words.For example, givens = "leetcode",dict = ["lee...
2016-07-05 23:03:35
153
leetcode: 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...
2016-07-04 23:16:38
134
原创 leetcode: Candy
问题描述:There are N children standing in a line. Each child is assigned a rating value.You are giving candies to these children subjected to the following requirements:Each child must have at le...
2016-07-04 22:57:24
163
leetcode: Gas Station
问题描述:There are N gas stations along a circular route, where the amount of gas at station i is gas[i].You have a car with an unlimited gas tank and it costs cost[i] of gas to travel from station i...
2016-07-04 21:44:02
108
原创 leetcode: Clone Graph
问题描述:Clone an undirected graph. Each node in the graph contains a label and a list of its neighbors. OJ's undirected graph serialization:Nodes are labeled uniquely.We use # as a separator...
2016-07-04 20:36:45
124
原创 leetcode: Palindrome Partitioning II
问题描述:Given a string s, partition s such that every substring of the partition is a palindrome.Return the minimum cuts needed for a palindrome partitioning of s.For example, given s = "aab",Ret...
2016-07-04 07:31:30
89
leetcode: Surrounded Regions
问题描述:Given a 2D board containing 'X' and 'O', capture all regions surrounded by 'X'.A region is captured by flipping all 'O's into 'X's in that surrounded region.For example,X X X XX O O X...
2016-07-03 23:06:08
132
leetcode: Sum Root to Leaf Numbers
问题描述:Given a binary tree containing digits from 0-9 only, each root-to-leaf path could represent a number.An example is the root-to-leaf path 1->2->3 which represents the number 123.Find ...
2016-07-03 21:54:35
117
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人