自定义博客皮肤VIP专享

*博客头图:

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

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

博客底图:

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

栏目图:

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

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+
  • 博客(127)
  • 资源 (1)
  • 收藏
  • 关注

原创 数据结构与算法-散列

理想情况下的散列表是仅包括一些数据项的具有固定大小的数组,数据项关键字通过散列函数被映射到数组的特定位置并存储。理想情况下的散列函数应该计算简单,并且保证任何两个数据项映射到不同的位置。但是这是不可能的。散列函数如果输入的关键字是整数,则一般的处理方式是key mod TableSizekey\ mod\ TableSize ,并且通常数组的大小TableSizeTableSize为素数。但是在J

2017-12-16 17:04:57 292

原创 数据结构与算法-伸展树

介绍伸展树是一种特殊的二叉查找树,其基本思想是当一个节点被访问后,需要经过一系列的AVL树的旋转操作将该节点推到根节点。伸展树不要求像AVL树那样保留树的高度或者平衡信息,但是可以保证开始连续MM次对树的操作最多花费O(logN)O(logN)时间。展开展开(splaying)操作是将访问的节点通过一系列旋转变为根节点的过程。假设节点XX是访问路径上非根节点,XX存在父节点PP和祖父节点GG。伸展树

2017-12-13 14:27:52 316

原创 数据结构与算法-二叉树

树树的实现 实现树的一种方法是在每一个节点除数据外还有一些链,使得该节点的每一个儿子都有一个链指向他,但是该节点儿子的数量是不知道的,可以采用如下的方式:public class TreeNode{ Object element; TreeNode firstChild;//该节点的第一个儿子 TreeNode nextSibling;//该节点的兄弟节点}节点nin

2017-12-04 10:21:41 306

原创 LeetCode-116. Populating Next Right Pointers in Each Node【二叉树同层节点构成链表】

题目描述Given a binary treestruct TreeLinkNode { TreeLinkNode *left; TreeLinkNode *right; TreeLinkNode *next;}Populate each next pointer to point to its next right node. If there is no next right n

2017-10-29 20:31:42 202

原创 LeetCode-115. Distinct Subsequences【动归】

题目描述Given a string S and a string T, count the number of distinct subsequences of S which equals T. A subsequence of a string is a new string which is formed from the original string by deleting some

2017-10-29 20:08:03 193

原创 LeetCode-114. Flatten Binary Tree to Linked List

题目描述Given a binary tree, flatten it to a linked list in-place.For example, Given 1 / \ 2 5 / \ \ 3 4 6The flattened tree should look like: 1 \ 2 \

2017-10-22 20:51:45 187

原创 ReentraintLock及AbstractQueueSychronizer

ReentraintLock AQS

2017-10-19 21:15:16 604

原创 LeetCode-113. Path Sum II

题目描述Given a binary tree and a sum, find all root-to-leaf paths where each path’s sum equals the given sum.题目及实例解题思路该题目与LeetCode-112有着相同的思路,只不过本题目需要将满足条件的路径上所有节点的值输出。代码/** * Definition for a binary tre

2017-10-16 20:36:38 140

原创 LeetCode-112. Path Sum

题目描述Given a binary tree and a sum, determine if the tree has a root-to-leaf path such that adding up all the values along the path equals the given sum.题目及实例地址解题思路给定一个二叉树和一个目标值target,问是否在存在从root节点都叶节点的

2017-10-16 20:31:26 164

原创 LeetCode-95. Unique Binary Search Trees II

题目描述Given an integer n, generate all structurally unique BST’s (binary search trees) that store values 1…n. For example, Given n = 3, your program should return all 5 unique BST’s shown below. 1

2017-10-12 10:39:46 150

原创 LeetCode-110. Balanced Binary Tree

题目描述Given a binary tree, determine if it is height-balanced. For this problem, a height-balanced binary tree is defined as a binary tree in which the depth of the two subtrees of every node never diff

2017-10-09 22:16:20 123

原创 LeetCode-109. Convert Sorted List to Binary Search Tree

题目描述Given a singly linked list where elements are sorted in ascending order, convert it to a height balanced BST.解题思路解题思路完全参考LeetCode-108只不过是将数组存储二叉树的元素变成了链表存储。代码/** * Definition for singly-linked lis

2017-10-09 22:02:03 232

原创 LeetCode-107. Binary Tree Level Order Traversal II

题目描述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). For example: Given binary tree [3,9,20,null,null,

2017-10-08 21:26:09 131

原创 LeetCode-108. Convert Sorted Array to Binary Search Tree

题目描述Given an array where elements are sorted in ascending order, convert it to a height balanced BST.解题思路首先想到的是递归的方式,首先取中间位置的元素构成root节点,然后左段元素中取中间位置的元素作为root节点的左节点,取右段元素中间位置的元素作为root节点的右节点,以此类推。 遍历的方式

2017-10-08 20:53:53 140

原创 LeetCode-106. Construct Binary Tree from Inorder and Postorder Traversal

题目描述Given inorder and postorder traversal of a tree, construct the binary tree. Note: You may assume that duplicates do not exist in the tree.解题思路根据二叉树中序遍历(左中右)和后序遍历(左右中)的结果恢复二叉树,和LeetCode-105相同的思路,也

2017-10-08 19:42:24 119

原创 LeetCode-105. Construct Binary Tree from Preorder and Inorder Traversal

题目描述Given preorder and inorder traversal of a tree, construct the binary tree. Note: You may assume that duplicates do not exist in the tree.解题思路根据二叉树的先序遍历(中左右)和后续遍历(左中右)恢复原来的二叉树。 1. 递归的方式求解,将该问题划分

2017-10-06 22:32:59 143

原创 LeetCode-104. Maximum Depth of Binary Tree

题目描述Given a binary tree, find its maximum depth. The maximum depth is the number of nodes along the longest path from the root node down to the farthest leaf node.解题思路求解树的最大高度,利用递归可以很容易的求解。代码/** * De

2017-10-05 22:18:01 122

原创 LeetCode-103. Binary Tree Zigzag Level Order Traversal

算法描述Given a binary tree, return the zigzag level order traversal of its nodes’ values. (ie, from left to right, then right to left for the next level and alternate between).For example: Given binary t

2017-10-05 22:13:42 137

原创 LeetCode-102. Binary Tree Level Order Traversal

题目描述Given a binary tree, return the level order traversal of its nodes’ values. (ie, from left to right, level by level). For example: Given binary tree [3,9,20,null,null,15,7], 3 / \ 9

2017-10-05 21:32:13 140

原创 LeetCode-101. Symmetric Tree

问题描述Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center). For example, this binary tree [1,2,2,3,4,4,3] is symmetric: 1 / \ 2 2 / \ / \ 3 4 4

2017-10-04 22:08:43 137

原创 LeetCode-100. Same Tree

题目描述Given two binary trees, write a function to check if they are equal or not. Two binary trees are considered equal if they are structurally identical and the nodes have the same value.解题思路利用递归的方式求解

2017-10-04 21:18:13 169

原创 LeetCode-98. Validate Binary Search Tree

题目描述Given a binary tree, determine if it is a valid binary search tree (BST). Assume a BST is defined as follows: The left subtree of a node contains only nodes with keys less than the node’s key. T

2017-10-04 10:19:23 119

原创 LeetCode-92. 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->5->NULL. Note: Given m, n satisfy the fo

2017-09-29 22:12:18 128

原创 LeetCode-93. Restore IP Addresses

题目描述Given a string containing only digits, restore it by returning all possible valid IP address combinations. For example: Given “25525511135”, return [“255.255.11.135”, “255.255.111.35”]. (Order d

2017-09-26 22:36:28 121

原创 LeetCode-91. Decode Ways

题目描述A message containing letters from A-Z is being encoded to numbers using the following mapping: ‘A’ -> 1 ‘B’ -> 2 … ‘Z’ -> 26 Given an encoded message containing digits, determine the total num

2017-09-26 10:38:38 129

原创 LeetCode-90. Subsets II

题目描述Given a collection of integers that might contain duplicates, nums, return all possible subsets. Note: The solution set must not contain duplicate subsets.解题思路这道题是subsets的变种,目前集合中允许有重复的元素,而结果集中不允许

2017-09-25 14:12:38 141

原创 43. Multiply Strings

一、算法描述Given two non-negative integers num1 and num2 represented as strings, return the product of num1 and num2.Note:The length of both num1 and num2 is < 110. Both num1 and num2 contains only digits

2017-09-25 11:13:28 123

原创 ThreadLocal的一点理解

最近在看Spring,了解到spring中绝大部分的bean都可以声明为singleton的,是因为spring对bean中的一些非线程安全的状态采用ThreadLocal来处理,让他们变成了线程安全的bean。例如在TranscationSynchronizationManaer中:public abstract class TranscationSynchronizationManage

2017-09-18 12:16:02 881

原创 Ubuntu Nginx+php+yaf安装

一、Nginx安装下载 wget -c http://nginx.org/download/nginx-1.4.2.tar.gz解压tar -xzvf nginx-1.4.2.tar.gz编译安装cd nginx-1.4.2./configure --prefix=/usr/php/nginx //安装的位置makemake install运行cd /usr/php/nginx/sbin/.

2017-09-12 19:24:36 505

转载 SFTP 搭建

基于 ssh 的 sftp 服务相比 ftp 有更好的安全性(非明文帐号密码传输)和方便的权限管理(限制用户的活动目录)。(转自https://my.oschina.net/sallency/blog/784022)1、开通 sftp 帐号,使用户只能 sftp 操作文件, 而不能 ssh 到服务器2、限定用户的活动目录,使用户只能在指定的目录下活动,使用 sftp 的 ChrootDirector

2017-07-25 11:36:37 313

原创 PHP-isset()与empty()比较

isset()方法如果一个变量未定义返回false如果一个变量定义未赋值或者赋值为null返回false对一个变量使用unset(),返回false如果一个变量定义且其值不为null,返回true。empty()方法若变量不存在,返回true若变量存在,变量被赋值为”“、0、”0”、NULL、、FALSE、array()、var $var; 以及没有任何属性的对象,返回true对一个

2017-07-21 12:10:26 168

原创 LeetCode-120.Triangle

问题描述给一个由数字组成的三角形,寻找从三角顶部到达三角底部所经历的数字之和最小的路径,并返回改路径上的数字之和。例如: 解题思路首先说明的一点,如果每步只寻找最小的路径(而不遍历全部的路径)得到的最终答案并不是全局最优解,因为一开始有可能把真个方向带偏,这样只会求得局部最优。Top-Down遍历。利用数组minlen[i][j]代表从三角顶端[0][0]到[i][j]的最短路径,minle

2017-07-10 22:35:44 196

原创 LeetCode- Add to List 88. Merge Sorted Array

题目给定两个排过序的数组nums1和nums2,nums1数组中的有效元素长度为m,其总长度为m+n;nums2数组中有效元素长度为n,现将两个数组合并到nums1中,并且数组中的元素按升序排列。解题思路首先将nums1中前m个有效的元素赋值到另一个数组中tmpArray,然后tmpArray和nums2中的元素从0开始逐个比较,将较小的元素放到nums1中。这种解题方式需要额外长度的数组。另一

2017-07-06 22:29:25 320

原创 LeetCode-86.Partition List

问题描述给定一个链表和一个值x,将链表中节点值大于等于x的节点移到链表的后半部分,要求链表的两部分需要保持原来的顺序。解题思路遍历链表,如果当前链表的值大于x,在新链表中添加该元素,原链表中删除该元素,当遍历完原链表后,在原链表的后面添加新链表即可。代码/** * Definition for singly-linked list. * public class ListNode { *

2017-07-05 22:10:45 169

原创 LeetCode-81.Search in Rotated Sorted Array II

问题描述给定一个数组和目标值,元素按照从小的大的顺序排列(数组元素允许重复),数组元素有可能旋转,判断该目标值是否存在数组中。例如:[0,1,2,4,5,6,7],旋转后可能为[4,5,6,7,0,1,2]。如果目标值为2,返回true。解题思路一开始打算先用二分法寻找数组的旋转点,后来发现这样因为重复元素的存在无法找到旋转点。比如:1,1,3,1,1,找到nums[middle]==num

2017-07-03 22:41:21 123

原创 LeetCode-80. Remove Duplicates from Sorted Array II

题目描述给定一个升序排序的int数组,允许每个数字最多重复两次,多余的数字不允许出现在数组的0-(n-1)的位置上,n即为去重后数组的长度。例如:给定数组【1,1,1,2,2,3】,返回去重后数组的长度为5,并且数组的前5个元素为【1,1,2,2,3】.解题思路利用两个位置指针first和second,变量tem记录上一个元素,count表示与tem相等的元素的个数,first代表当前元素的

2017-07-02 21:41:08 143

原创 LeetCode-79. Word Search

题目描述给定一个二维字符矩阵和一个单词,判定该矩阵中地临近地字符能否组成这个单词。要求:临近地意思是指两字符只能水平临近或者竖直临近;每个位置地字符只能使用一次。解题思路使用回溯算法,采用递归实现,需要判定边界条件,需要一个数组记录走过地位置。代码public class Solution { private boolean[][] flags; public boolean exi

2017-07-01 09:57:18 163

原创 LeetCode-77.Combinations

题目描述给定两个整数n和k,求1.2.3.4……n中所有可能出现的k个数的组合。如果n=4,k=2,则答案为[ [2,4],[3,4],[2,3],[1,2],[1,3],[1,4] ]。解题思路采用递归的方式解决,上面地答案简单整理一下可以看成是1,2;1,3;1,4;2,3;2,4;3,4;对于每个位置的数利用递归函数求解包含与他右边距离为1地数地解,然后求解距离为2,然后依次递增,直到当前数+

2017-06-27 23:00:53 189

原创 LeetCode-75. Sort Colors

题目描述给定一个由n个元素的数组,元素仅包含0,1,2三种形式,求数组排序的结果。不允许使用Arrays.sort()函数。解题思路借鉴快排的思想,利用双指针从数组的左右两路扫描数组。满足left小于right,则开启总循环。如果右指针遇到2,则继续扫描right–;否则,停止扫描。如果左指针遇到2,则停止扫描,与右指针指向的元素做交换;如果左指针遇到1,将该位置添加到列表中,将继续扫描left+

2017-06-25 09:20:34 181

原创 74. Search a 2D Matrix

问题描述给定一个矩阵和目标值,其中矩阵满足:矩阵每行的元素都保持从小到大的顺序;矩阵每行第一个元素比上一行最后一个元素要大。寻找该目标值是否村在矩阵中。解题思路由题意可以得知,矩阵中的每行元素和每列元素都保持递增,因此可以利用两次二分查找来求解。现在第一列中寻找处目标值所在的行,然后在该行中寻找目标值。代码public class Solution { public boolean se

2017-06-23 22:22:56 134

51 控制超声波测距

使用51,发射端是P1^1,接收端使用的是外部中断零,数码管显示,距离的单位是厘米

2013-05-15

空空如也

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

TA关注的人

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