自定义博客皮肤VIP专享

*博客头图:

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

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

博客底图:

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

栏目图:

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

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+
  • 博客(126)
  • 资源 (2)
  • 收藏
  • 关注

原创 sql 排名函数 rank() , row_number() , dense_rank() over

参考: rank,dense_rank,row_number使用和区别一、语法(用法): rank() over([partition by col1] order by col2) tt dense_rank() over([partition by col1] order by col2) tt row_number() over([partition by

2015-09-12 18:16:57 614

原创 海量数据处理问题

海量数据处理 算法总结海量数据求中位数

2015-09-05 22:38:30 547

原创 4Sum(****) 基于3Sum

题目: 在array中找到所有的组合 a + b + c + d = target , 组合不重复且a < b < c < d数组排序对每一个数组中的元素arr[i] , 求3Sum target = target - arr[i] 时间复杂度 < O(n^3)3Sum暴力的话,时间复杂度为O(n^3) , 但是对于排序的数组,对于 下标 i , j 如果 i < j arr[i] + arr

2015-08-31 21:18:10 385

原创 基于快排 查找数组中出现三次的元素(***)

题目: 数组中有一个元素出现3次,其余出现两次 找到出现三次的元素, 要求空间复杂度 O(1) // 不要想用Map 时间复杂度不大于O(nlgn)思路: 快排,count 记录在比较过程中与基准元素相等的个数,如果==3 , 则直接返回//找到出现三次的数,数组中的元素要么出现两次就是三次 public static int quickSort(int[] arr , int l

2015-08-30 22:01:27 874

原创 Spiral Matrix(**)

题目: 螺旋化输出矩阵 For example, Given the following matrix:[ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ] You should return [1,2,3,6,9,8,7,4,5].思路: 递归 1. 以一圈为一次递归 比如上面的 1 2 3 6 9 8 7 4 2. 设置四个指针 top b

2015-08-30 19:05:20 371

原创 Word Search (***)

题目: Given a 2D board and a word, find if the word exists in the grid. The word can be constructed from letters of sequentially adjacent cell, where “adjacent” cells are those horizontally or vertical

2015-08-30 16:42:30 374

原创 Word Loadder II (***) -- BFS DFS

题目 : 和 word Loadder 不同的是他要列出所有最短的路径思路 : 1. BFS生成从start 到 end 节点与高度的map 2. DFS从 end节点,递归遍历到start, 找出所有可能的路径代码来自 : Leetcode Word Ladder II 解题报告public class Solution { //记录每个单词所在的层数 HashMap

2015-08-26 22:14:19 430

原创 word Loadder I(****) -- BFS

题目:Given two words (beginWord and endWord), and a dictionary, find the length of shortest transformation sequence from beginWord to endWord, such that:Only one letter can be changed at a time Each int

2015-08-26 21:14:08 413

原创 Interleaving String(*****)

参考: Leetcode: Interleaving String 递归和DP两种方法解答,解释的很清楚题目:交叉字符串, For example, Given: s1 = “aabcc”, s2 = “dbbca”,When s3 = “aadbbcbcac”, return true. When s3 = “aadbbbaccc”, return false.方法一:递归方法每次都是取

2015-08-17 21:54:58 343

原创 Generate Parentheses(****)

题目: Given n pairs of parentheses, write a function to generate all combinations of well-formed parentheses. For example, given n = 3, a solution set is: “((()))”, “(()())”, “(())()”, “()(())”, “()()

2015-08-16 17:30:10 584

原创 Basic Calculator II(**)

题目: 计算输入字符串的值 “3 + 4 2 / 3 ”思路: 用栈来存值 public class Solution { public static int calculate(String s) { char[] chars = s.trim().toCharArray(); LinkedList<Integer> numStack = new Li

2015-08-16 17:12:00 342

原创 Group Anagrams(***)

题目: Given an array of strings, group anagrams together.For example, given: [“eat”, “tea”, “tan”, “ate”, “nat”, “bat”], Return: [ [“ate”, “eat”,”tea”], [“nat”,”tan”], [“bat”] ]思路: 1. 对每一个单词

2015-08-16 13:00:31 747

原创 Java 集合类的一点总结

今天碰到的一个异常:java.util.HashMap$Values cannot be cast to java.util.List 因为我想这样:ListList<List<String>> groups = new ArrayList<> ( map.values());集合类结构图: 数组与集合类之间的转换集合 -> 特定类型的数组:List<String> group = gro

2015-08-16 12:44:43 487

原创 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.思路: 1. 一个遍历指针 ite, 从头遍历 2. 一个尾部指针 tail,总是指向当前的

2015-08-15 15:30:04 353

原创 Reverse Linked List(****)

题目: 翻转链表思路: 1. head一直指向头节点 2. p 则是从头到尾遍历链表public class Solution { public ListNode reverseList(ListNode head) { if(head == null) return head; // head一直指向头节点, 而p 则是从头到尾遍历链表

2015-08-13 21:23:50 346

原创 Lowest Common Ancestor of a Binary Tree(***)

题目:求二叉树的最近公共子祖先 , 注意这里不是BST解题思路: 求LCA of BT , 就三种情况: 1. p ,q 为root的左右子树中的节点 == > return root; 2. p q 在root的一棵子树中 ,p为父辈 ==> return p; 3. q为父辈 ==> return q; 所以,实际就是一个遍历的过程,只是在遍历的时候,加一些判断的操作!public c

2015-08-13 20:57:08 336

原创 Count Complete Tree Nodes(****)

题目:计算完全二叉树的节点个数思路: 1. 不是暴力解决,那样太简单了,遍历一次即可 2. 因为是完全二叉树,所以: - 满二叉树的节点 = 2^k-1 k为高度 - 完全二叉树中一定有子树为满二叉树public class Solution { public int countNodes(TreeNode root) { if(root == null

2015-08-12 21:58:30 341

原创 LCA in BST

题目:Given a binary search tree (BST), find the lowest common ancestor (LCA) of two given nodes in the BST.思路: 两节点 p , q , 分多中情况考虑, 因为是BST, 如果 p < root , q > root ==> LCA = root 如果 p = Max(p , q ) < ro

2015-08-09 17:22:31 662

原创 Kth Smallest Element in a BST

思路: 1 . 可以设置一个全局变量 , 中序遍历即可 2. 不是递归总序遍历,而是迭代式public class Solution { public int kthSmallest(TreeNode root, int k) { LinkedList<TreeNode> stack = new LinkedList<> (); stack = getLe

2015-08-09 16:49:26 327

原创 Path Sum II(****)

题目: root 到 叶子节点 sum = 给定值 , 返回各个节点值思路: 1. 前序遍历 , 用一个链表来存储依次遍历的值,直到叶子节点,然后计算链表的和 2. 也就是说,链表存的,就是root到当前 叶子节点所经历的节点的val 3. 所以,在遍历的过程 , 还必须记得remove List中值 == > List == Stack!public class Solution {

2015-08-09 15:48:52 237

原创 树的层序遍历(深度优先 和 队列)

题目: Given a binary tree, return the bottom-up level order traversal of its nodes’ values. (ie, from left to right, level by level from leaf to root).DFS算法:public List<List<Integer>> levelOrderBottom(Tr

2015-08-09 11:16:51 606

原创 Kth Largest Element in an Array

题目: 查找(无序)数组中第K大的元素 == > O(n)思路: 1. 快排的时候,partition() == > 返回的就是某个元素的位置 通过比较这个元素idx 与 待查找元素的idx , 缩小查找范围public class Solution { public int findKthLargest(int[] nums, int k) { int len

2015-08-09 11:13:53 290

原创 Binary Tree Inorder Traversal

题目:迭代中序遍历思路: 1. 递归 ==> 栈 2. 对于每个节点,向左遍历,所有节点入栈,直到叶子节点/** * Definition for a binary tree node. * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode(

2015-08-08 16:32:44 282

原创 Construct Binary Tree from Preorder and Inorder Traversal

题目:根据中序遍历和前序遍历数组构建二叉树解题思路: 比如 : pre = { A , B , D , E , C} in= {D , B , E , A , C} 1. A 为root, 在中序遍历中 , 找到左子树节点为D, B , E , 右子树 : C 2. A左子树根节点 = B , 同理找到它的左右子树… 3. 如此递归/** * Definition for a binar

2015-08-05 22:21:52 371

原创 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. Binary Tree Maximum Path Sum – LeetCode 解题思路: 1. 设一个max的全局变量记录遍历过程中的最大值 2. 对于任意node,计算出它两棵子树中的最长

2015-08-05 21:31:46 354

原创 Binary Tree Right Side View

题目:Given a binary tree, imagine yourself standing on the right side of it, return the values of the nodes you can see ordered from top to bottom.解题思路: 1. 右子树的高度 >= 左子树 , easy ; 2. 左子树 > 右子树?

2015-08-04 21:39:29 273

原创 Binary Search Tree Iterator

题目:写一个BST遍历器 1. 初始化遍历器 2. next() will return the next smallest number in the BST 3. next() and hasNext() should run in average O(1) time and uses O(h) memory, where h is the height of

2015-08-04 20:48:38 295

原创 synchronized 及 线程通信

线程通信推荐文章线程通信通信方式共享对象wait notify 和 notifyAll机制 (并发包中的Condition)注意点不要在字符串常量或全局对象中调用wait(),因为可能调用notify或notifyAll的时候 不知道唤醒了哪一个,或者为什么都唤醒了?因为多个引用指向的是同一个对象!丢失信号:如果一个线程先于被通知线程调用wait()前调用了notify(),等待的线程将

2015-08-03 22:46:09 397

原创 面试准备之数据结构

跳表 skipList浅析SkipList跳跃表原理及代码实现链表与跳表的异同:传统意义的单链表是一个线性结构,向有序的链表中插入一个节点需要O(n)的时间,查找操作需要O(n)的时间。如果我们使用图1所示的跳跃表,就可以减少查找所需时间为O(n/2),因为我们可以先通过每个节点的最上面的指针先进行查找,这样子就能跳过一半的节点。比如我们想查找19,首先和6比较,大于6之后,在和9进行比较,然后在和

2015-08-02 19:41:16 688

原创 面试总结之Java基础(未完工)

1. JVM相关1.1. 内存模型图片来源 : 深入理解Java内存模型(一)——基础 jvm体系结构 运行时数据区: 1.2. 类加载机制和JVM体系结构1.3. 垃圾回收机制Java 内存模型及GC原理 JDK5.0中JVM堆模型、GC垃圾收集详细解析分代堆模型1) 在Young Generation(年轻代)中,有一个叫Eden Space的空间,主要是用来存放新生的对象,还有两个Su

2015-07-28 22:21:21 335

原创 实习记录

跨域操作HTTP访问控制(CORS)Spring MVC RESTSSO单点登录Json :jsckson框架CopyOnWriteArrayList

2015-07-27 17:00:12 413

转载 面试准备之多线程(转)

原文 : Java线程面试题 Top 50不管你是新程序员还是老手,你一定在面试中遇到过有关线程的问题。Java语言一个重要的特点就是内置了对并发的支持,让Java大受企业和程序员的欢迎。大多数待遇丰厚的Java开发职位都要求开发者精通多线程技术并且有丰富的Java程序开发、调试、优化经验,所以线程相关的问题在面试中经常会被提到。在典型的Java面试中, 面试官会从线程的基本概念问起, 如:为什么你

2015-07-26 22:25:44 435

原创 面试准备之数据库部分

收藏文章: 数据库建表原则数据库范式1NF 原子性,表中列不能在分,比如地名可以有省,市,区..构成,如果把省市区放在一个字段里面,那么 陕西省的人,省都是陕西,这样不就是一种冗余,而且,你想统计所有陕西的人,那么你就只能通过like 来模糊匹配…. 2NF 要求数据表里的所有数据都要和该数据表的主键有完全依赖关系;如果有哪些数据只和主键的一部份有关的话,它就不符合第二范式。同时可以得

2015-07-26 22:22:36 522

原创 JBoss 部署EJB应用并在客户端调用

参考文章 : JBoss AS 7 remote EJB client tutorial                                  EJB invocations from a remote client using JNDI       任务 : 通过Jboss来部署EJB应用,然后在客户端调用!很简单,可是如果你是       第一次用, 难免遇到许多坑。

2015-07-25 22:22:25 1405

原创 enum枚举类的一个简单例子

定义一个枚举类: public enum Time {// 通过构造方法给常量传值 DATE1("2016-6-26 12:14:10"), DATE2("2016-6-26 12:14:10"), DATE3("2016-6-26 12:14:10"), DATE4("2016-6-26 12:14:10"), DATE5("2016-6-26 12:14:10"

2015-07-25 22:22:19 4990

原创 头尾指针

1.  三数和  3SUM     2. 数组中的元素能构成的最大面积(Container With Most Water)

2015-07-25 22:22:13 582

原创 Container With Most Water (头尾指针的妙用)

对于数组 A , 怎么求的Max((j - i) * [min (A[i] , A[j])]) , 其中 i , j     这道题目, 暴力的话,很容易, O(n^2) , 可是采用头尾指针的方法可以在O(n)的时间内完成!    O(n) 的代码 及其简单,就是头尾指针,谁小谁移动,然后,求两个指针间的面积,再更新   最大面积即可。    但是,为什么?为什么这个

2015-07-25 22:22:04 321

原创 Reverse Integer

注意:      这道题目不难,但是多处要注意:      1. 0结尾      2. 反转过来是否越界      3. 负数与正数  // 可以利用 StringBuffer 的 reverse()方法的。   public class Solution { public int reverse(int x) { if(x == 0 ||

2015-07-25 22:21:59 285

原创 二叉树反转(Invert Binary Tree )

思路:       一次前序遍历    public class Solution { public TreeNode invertTree(TreeNode root) { if(root == null) return root; TreeNode tmp = root.left; root.left = root

2015-07-25 22:21:53 442

原创 最长回文子串

思路:      分两种情况考虑:      第一种:奇数回文,比如:“aba”      第二种:偶树回文 ,比如:“adda”      然后遍历字符串,以该字符为中心,检查它的前后能够构成上述两种情况中的      回文串。      时间复杂度: O(n ^2)       代码: public class Solution { //最长回文子

2015-07-25 22:21:47 313

FourSum四数和

四数和

2015-08-31

c++程序设计语言(c++之父)课后习题答案

c++之父编的那本c++课后习题的参考答案

2014-07-12

空空如也

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

TA关注的人

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