喵星人与汪星人
huntfor · 共 160 篇文章
Hibernate4 buildSessionFactory过时处理办法
这几天做毕设,用到Hibernate,发现buildSessionFactory方法,上网找资料得到的答案如下: public void test() { Configuration cfg = new Configuration(); cfg.configure(); ServiceRegistry sr = new ServiceRegistryBuilder().applySettings(cfg.getProperties()).buildServiceRegistry(); SessionFactory sf = cfg.buildSessionFactory(sr); Sessi…
【java】SQL server 连接异常
记录每次遇到的bug与异常 jdbc的下载地址与DBMS的配制方法见下文http://www.360doc.com/content/14/0806/02/15319145_399731507.shtml 我在测试链接的时候遇到了如下异常: 数据库驱动加载成功... com.microsoft.sqlserver.jdbc.SQLServerException: 用户 'sa' 登录失败。 ClientConnectionId:ea4142b1-ae5c-4618-b6a5-c827b5205235 at com.microsoft.sqlserver.jdbc.SQLServerExcept…
2014-12-10 16:23 · java · 数据库 · SQL server2012 · 评论(0)
[leetcode]Add Two Numbers
又是一篇漏网之鱼,请大家移步新博文地址: [leetcode]Add Two Numbers 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 as a linked list. Input: (2 -> 4 -> 3) + (5 -…
[leetcode]Remove Duplicates from Sorted Array
新博文地址: [leetcode]Remove Duplicates from Sorted Array II Remove Duplicates from Sorted Array II Follow up for "Remove Duplicates": What if duplicates are allowed at most twice? For example, Given sorted array A = [1,1,1,2,2,3], Your function should return length = 5, and A is now [1,1,2,2,3]. 具有又是漏网…
[leetcode]Reorder List
新博文地址: [leetcode]Reorder List 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 {1,4,2,3}. 算法思路: 设置快慢指针将前半段与后半段分开,然后将后半段逆序,再逐个插入前半段,时间复杂度O(n),空间…
[leetcode]Plus One
这道题包含在难度一的 习题汇总 里面。现在单独列出来。 新博文换了一种思路,代码更简洁,空间更节省 新博文地址: [leetcode]Plus One 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. 题目大意是,一个非负数用数组表示,对这个数+1,返回+1后的数组结果 第一反应肯…
终于刷完一遍了【搬家】
博客搬家鸟,请 戳这里 : 喵星人与汪星人 第二遍刷才发现第一遍的代码有多愁淫....新博文的算法,无论是在复杂度,还是代码简洁度、可读性上,都要优于本博客的代码,建议大家看博客的时候,直接点新博文地址。新博文不断更新中 终于刷完一遍了,马克一下 151道题目,完全自己做的大概有120+道左右,借鉴别人思路的大概20道左右,抄的大概10道左右..... leetcode151道题目应该在本博客中都有记载。 不容易 第二遍可能把博客搬家,搬家地址会更新在这篇博文中 第二遍会对每一道题进行优化,并对每类问题进行分类,并尽量在时间、空间、代码可读性上做的更好 以上
2014-07-03 00:38 · 吐槽 · 评论(0)
[leetcode]Sudoku Solver
新博文地址: [leetcode]Sudoku Solver Sudoku Solver Write a program to solve a Sudoku puzzle by filling the empty cells. Empty cells are indicated by the character '.'. You may assume that there will be only one unique solution. 好了,最后一道题了,一直对数独特别害怕,不知道为啥,但是仔细看了这道题,貌似没啥难度,跟八皇后问题一样,典型的回溯算法,当然也可以用迭代实现,我同学用了 …
[leetcode]Scramble String
Scramble String Given a string s1, we may represent it as a binary tree by partitioning it to two non-empty substrings recursively. Below is one possible representation of s1 = "great": great / \ gr eat / \ / \ g r e at / \ a t To scramble the string, we may choose any non-leaf node and swap its tw…
[leecode]Word Ladder II
Word Ladder II Given two words (start and end), and a dictionary, find all shortest transformation sequence(s) from start to end, such that: Only one letter can be changed at a time Each intermediate word must exist in the dictionary For example, Given: start = "hit" end = "cog" dict = ["hot","dot"…
[leetcode]Clone Graph
新博文地址: [leecode]Clone Graph 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 for each node, and , as a separator for node label and each neighbor of th…
[leetcode]Max Points on a Line
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. 坐标轴上面有n个点,求共线的最大点数。 这道题是leetcode上通过率最低的,但是绝对不是最难的,几点共线我们可以根据y = k x + b算出: 1. 平行于y轴的垂线斜率设为最大值,平行于x轴的线与普通斜线没啥区别,不需要做特殊处理; 2. 比较棘手的是重复点 这道题,我重构了一个数据结构,包含了k,b从而确定了每一条线,二重遍历坐标轴中每一个点(…
[leetcode]Binary Tree Maximum Path Sum
新博文地址: [leetcode]Binary Tree Maximum Path Sum Binary Tree Maximum Path Sum Given a binary tree, find the maximum path sum. The path may start and end at any node in the tree. For example: Given the below binary tree, 1 / \ 2 3 Return 6. 这道题是非常好的一道题,树,常规做法是遍历,遍历的做法往往用dfs,代码简单,可读性强。这道题与常规的树的题目不同的一点是,…
[leetcode]Maximal Rectangle
Maximal Rectangle Given a 2D binary matrix filled with 0's and 1's, find the largest rectangle containing all ones and return its area. 最土的做法无疑就是遍历矩阵中的所有矩形,时间复杂度为O(n^2 * m ^2)不用试估计也会超时了,看了 讨论组 里面有位大神提供了这样的思路: This question is similar as [ Largest Rectangle in Histogram ]: You can maintain a row len…
[leetcode]Interleaving String
新博文地址: [leetcode]Interleaving String 建议大家看新博文,自己想的算法比本博文借鉴的算法要更容易理解。 Interleaving String Given s1, s2, s3, find whether s3 is formed by the interleaving of s1 and s2. For example, Given: s1 = "aabcc", s2 = "dbbca", When s3 = "aadbbcbcac", return true. When s3 = "aadbbbaccc", return false. 题目大意: 两个字…