自定义博客皮肤VIP专享

*博客头图:

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

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

博客底图:

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

栏目图:

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

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+
  • 博客(35)
  • 收藏
  • 关注

转载 MATLAB squeeze 函数

squeeze  除去size为1的维度B = squeeze(A)描述:B = squeeze(A),B与A有相同的元素,但所有只有一行或一列的维度(a singleton dimension)被去除掉了。A singleton dimension的特征是size(A,dim) = 1。二维阵列不受squeeze影响; 如果 A 是一个row or column矢量或

2015-05-25 15:34:28 1000

原创 [LeetCode][Java] 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 ne

2015-05-23 21:25:22 700

原创 [LeetCode][Java] Remove Element

题目:Given an array and a value, remove all instances of that value in place and return the new length.The order of elements can be changed. It doesn't matter what you leave beyond the new len

2015-05-23 21:16:19 568

原创 [LeetCode][Java] 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-05-23 20:59:54 582

原创 [LeetCode][Java] Swap Nodes in Pairs

题目:Given a linked list, swap every two adjacent nodes and return its head.For example,Given 1->2->3->4, you should return the list as 2->1->4->3.Your algorithm should use only constant

2015-05-23 20:32:44 578

原创 [LeetCode][Java] Best Time to Buy and Sell Stock

题目:Say you have an array for which the ith element is the price of a given stock on day i.If you were only permitted to complete at most one transaction (ie, buy one and sell one share of th

2015-05-22 21:28:59 645

原创 [LeetCode][Java] Unique Paths

题目:A robot is located at the top-left corner of a m x n grid (marked 'Start' in the diagram below).The robot can only move either down or right at any point in time. The robot is trying to r

2015-05-22 21:19:43 542

原创 [LeetCode][Java] Merge Two Sorted Lists

题目:Merge two sorted linked lists and return it as a new list. The new list should be made by splicing together the nodes of the first two lists.题意:将两个单链表合并,合并一个新的单链表。算法分析:比较容易,注意此题并未要求删除

2015-05-22 20:19:39 474

原创 [LeetCode][Java] Minimum Path Sum

题目:Given a m x n grid filled with non-negative numbers, find a path from top left to bottom right which minimizes the sum of all numbers along its path.Note: You can only move either down or

2015-05-22 15:59:00 834

原创 [LeetCode][Java] Reverse Linked List

题目:Reverse a singly linked list.题意:倒转单链表.算法分析:方法一:将单链表转化为数组,利用数组倒序重建新的单链表。代码如下:/** * Definition for singly-linked list. * public class ListNode { * int val; * ListNode ne

2015-05-21 21:36:47 669

原创 [LeetCode][Java] Convert Sorted Array to Binary Search Tree

题目:Given an array where elements are sorted in ascending order, convert it to a height balanced BST。题意:给定一个数组,其中的数组元素降序排列,将其转化为平衡二叉查找树。算法分析:首先明白概念二叉查找树和平衡二叉查找树:二叉排序树或者是一棵空树,或者是具有下列性质的二叉树

2015-05-21 20:20:23 585

原创 [LeetCode][Java] Climbing Stairs

题目:You are climbing a stair case. It takes n steps to reach to the top.Each time you can either climb 1 or 2 steps. In how many distinct ways can you climb to the top?题意:假设爬梯子,你需要n步跑到顶。

2015-05-21 20:02:02 505

原创 [leetCode][Java] Remove Duplicates from Sorted List

题目:Given a sorted linked list, delete all duplicates such that each element appear only once.For example,Given 1->1->2, return 1->2.Given 1->1->2->3->3, return 1->2->3.题意:给定一个有序单

2015-05-21 19:47:49 495

原创 [LeetCode][Java] Maximum Subarray

题目:Find the contiguous subarray within an array (containing at least one number) which has the largest sum.For example, given the array [−2,1,−3,4,−1,2,1,−5,4],the contiguous subarray [4,−

2015-05-21 19:15:27 485

原创 [LeetCode][Java] Majority Element

题目:Given an array of size n, find the majority element. The majority element is the element that appears more than ⌊ n/2 ⌋ times.You may assume that the array is non-empty and the majo

2015-05-21 14:40:15 541

原创 [LeetCode][Java] Single Number II

题目:Given an array of integers, every element appears three times except for one. Find that single one.Note:Your algorithm should have a linear runtime complexity. Could you implement it wi

2015-05-21 14:23:22 622

原创 [LeetCode][Java] Search Insert Position

题目:Given a sorted array and a target value, return the index if the target is found. If not, return the index where it would be if it were inserted in order.You may assume no duplicates in t

2015-05-21 14:02:05 513

原创 [LeetCode][Java] 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 / 3return [1,2,3].题意:二叉树先序遍历

2015-05-20 21:17:01 543

原创 [LeetCode][Java] Unique Binary Search Trees

题目:Given n, how many structurally unique BST's (binary search trees) that store values 1...n?For example,Given n = 3, there are a total of 5 unique BST's. 1 3 3 2

2015-05-20 21:09:31 545

原创 [LeetCode][Java] Binary Tree Inorder Traversal

题目:Given a binary tree, return the inorder traversal of its nodes' values.For example:Given binary tree {1,#,2,3}, 1 \ 2 / 3return [1,3,2].Note: Recursive

2015-05-20 20:08:08 495

原创 [LeetCode][Java] Populating Next Right Pointers in Each Node

题目:Given a binary tree struct TreeLinkNode { TreeLinkNode *left; TreeLinkNode *right; TreeLinkNode *next; }Populate each next pointer to point to its next rig

2015-05-20 19:44:10 506

原创 [LeetCode][Java] 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?题意:给定一个链表,判断链表中是否存在循环圈。算法分析:  * 利用快慢指针slow,fast,slow指针每次走一步,fas

2015-05-20 19:30:16 451

原创 [LeetCode][Jave] Excel Sheet Column Number

题目:Given a column title as appear in an Excel sheet, return its corresponding column number.For example: A -> 1 B -> 2 C -> 3 ... Z -> 26 AA -> 27 AB -> 28 题意:

2015-05-20 19:19:13 497

原创 [LeetCode][Java] Number of 1 Bits

题目:Write a function that takes an unsigned integer and returns the number of ’1' bits it has (also known as the Hamming weight).For example, the 32-bit integer ’11' has binary representation

2015-05-20 18:46:13 673

原创 [LeetCode][Jave] Best Time to Buy and Sell Stock II

题目:Say you have an array for which the ith element is the price of a given stock on day i.Design an algorithm to find the maximum profit. You may complete as many transactions as you like (i

2015-05-19 20:50:49 584

转载 二叉查找树及平衡二叉查找树

二叉查找树(BST)前一篇介绍了树,却未介绍树有什么用。但就算我不说,你也能想得到,看我们Windows的目录结构,其实就是树形的,一个典型的分类应用。当然除了分类,树还有别的作用,我们可以利用树建立一个非常便于查找取值又非常便于插入删除的数据结构,这就是马上要提到的二叉查找树(Binary Search Tree),这种二叉树有个特点:对任意节点而言,左子(当然了,存在的话)的值总是小于本身

2015-05-16 10:46:36 765

原创 [LeetCode][Java] 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.题目大意:给定一棵二叉树,找到它的最大深度。

2015-05-15 21:52:22 646

原创 [LeetCode][Java] 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.题意:

2015-05-15 21:36:17 516

原创 [LeetCode][Java] 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 us

2015-05-15 21:27:57 632

转载 单链表的倒序

单链表的翻转是一道很基本的算法题。        方法1:将单链表储存为数组,然后按照数组的索引逆序进行反转。        方法2:使用三个指针遍历单链表,逐个链接点进行反转。        方法3:从第2个节点到第N个节点,依次逐节点插入到第1个节点(head节点)之后,最后将第一个节点挪到新表的表尾。        方法1的问题是浪费空间。方法2和方法3效率相

2015-05-14 19:52:08 5341

原创 回溯算法

回溯法(英语:backtracking)是暴力搜寻法中的一种。       回溯法采用试错的思想,它尝试分步的去解决一个问题。在分步解决问题的过程中,当它通过尝试发现现有的分步答案不能得到有效的正确的解答的时候,它将取消上一步甚至是上几步的计算,再通过其它的可能的分步解答再次尝试寻找问题的答案。回溯法通常用最简单的递归方法来实现,在反复重复上述的步骤后可能出现两种情况:找到一个可能

2015-05-14 10:37:16 1039

转载 Java中HashSet HashTable HashMap的区别

(1)HashSet是set的一个实现类,hashMap是Map的一个实现类,同时hashMap是hashTable的替代品(为什么后面会讲到).(2)HashSet以对象作为元素,而HashMap以(key-value)的一组对象作为元素,且HashSet拒绝接受重复的对象.HashMap可以看作三个视图:key的Set,value的Collection,Entry的Set。 这里Has

2015-05-12 20:58:46 778

转载 java中queue的使用

Queue接口与List、Set同一级别,都是继承了Collection接口。LinkedList实现了Queue接 口。Queue接口窄化了对LinkedList的方法的访问权限(即在方法中的参数类型如果是Queue时,就完全只能访问Queue接口所定义的方法 了,而不能直接访问 LinkedList的非Queue的方法),以使得只有恰当的方法才可以使用。BlockingQueue 继承了Q

2015-05-10 17:06:54 501

转载 java源码分析之LinkedList

LinkedList也和ArrayList一样实现了List接口,但是它执行插入和删除操作时比ArrayList更加高效,因为它是基于链表的。基于链表也决定了它在随机访问方面要比ArrayList逊色一点。    除此之外,LinkedList还提供了一些可以使其作为栈、队列、双端队列的方法。这些方法中有些彼此之间只是名称的区别,以使得这些名字在特定的上下文中显得更加的合适。   

2015-05-06 17:21:25 391

转载 java 字符串转化为整数溢出问题处理

1、思路及注意事项参考:http://blog.sina.com.cn/s/blog_514c89a90100d7qh.html概括起来有几种情况1)字符串开头是“+”号或“-”号的处理2)非法字符的判断(不是数字)3)整数溢出问题。    看看Java函数库中的Integer.parseInt(String sting)的源码如何处理这些问题的

2015-05-03 16:54:16 7067

空空如也

空空如也

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

TA关注的人

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