自定义博客皮肤VIP专享

*博客头图:

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

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

博客底图:

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

栏目图:

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

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+
  • 博客(32)
  • 资源 (1)
  • 问答 (1)
  • 收藏
  • 关注

原创 寻找丑数

题目描述 把只包含因子2、3和5的数称作丑数(Ugly Number)。例如6、8都是丑数,但14不是,因为它包含因子7。 习惯上我们把1当做是第一个丑数。求按从小到大的顺序的第N个丑数。析:后面的丑数肯定是由前面的丑数求出来的// 用i2,i3,i5保存当前乘2 3 5结果最小的数的位置 public int GetUglyNumber_Solution2(int n) {

2017-03-30 16:32:05 306

原创 判断是否是栈的出栈顺序

输入两个整数序列,第一个序列表示栈的压入顺序,请判断第二个序列是否为该栈的弹出顺序。假设压入栈的所有数字均不相等。例如序列1,2,3,4,5是某栈的压入顺序,序列4,5,3,2,1是该压栈序列对应的一个弹出序列,但4,3,5,1,2就不可能是该压栈序列的弹出序列。(注意:这两个序列的长度是相等的)析:借助一个栈 public boolean IsPopOrder(int [] pushA,in

2017-03-28 10:17:31 632

原创 判断树是否结构对称

题目描述 请实现一个函数,用来判断一颗二叉树是不是对称的。注意,如果一个二叉树同此二叉树的镜像是同样的,定义其为对称的。析: 法1:网友方法boolean isSymmetrical(TreeNode pRoot) { if (pRoot == null) return true; return f(pRoot.left,pRoot.righ

2017-03-24 17:27:14 617

原创 二叉树中序遍历的下一个结点

给定一个二叉树和其中的一个结点,请找出中序遍历顺序的下一个结点并且返回。注意,树中的结点不仅包含左右子结点,同时包含指向父结点的指针。析:每次先找当前结点的右子树中序遍历的第一个结点,如果非空就返回,如果为空,就让当前结点逐步向祖宗方向寻找,如果某个祖宗是前一祖宗的左结点,就返回该结点。否则返回null/*public class TreeLinkNode { int val; T

2017-03-24 16:02:01 424

原创 判断B是否是A的子结构

题目描述 输入两棵二叉树A,B,判断B是不是A的子结构。(ps:我们约定空树不是任意一个树的子结构)public class Solution { public boolean HasSubtree(TreeNode root1,TreeNode root2) { if(root2==null) return false; if(root1==null &&

2017-03-23 22:19:02 421

原创 链表反转

题目描述 输入一个链表,反转链表后,输出链表的所有元素。/*public class ListNode { int val; ListNode next = null; ListNode(int val) { this.val = val; }}*/public class Solution { public ListNode Revers

2017-03-23 14:59:15 173

原创 用两个栈实现队列

用两个栈来实现一个队列,完成队列的Push和Pop操作。 队列中的元素为int类型。 Stack<Integer> stack1 = new Stack<Integer>(); Stack<Integer> stack2 = new Stack<Integer>(); public void push(int node) { stack1.push(node);

2017-03-23 10:34:29 300

原创 根据前序、中序遍历创建二叉树

题目描述 输入某二叉树的前序遍历和中序遍历的结果,请重建出该二叉树。假设输入的前序遍历和中序遍历的结果中都不含重复的数字。例如输入前序遍历序列{1,2,4,7,3,5,6,8}和中序遍历序列{4,7,2,1,5,3,8,6},则重建二叉树并返回。// 自己的思路:/** * Definition for binary tree * public class TreeNode { *

2017-03-22 23:48:03 522

原创 链表应用:奇数位丢弃

对于一个由0..n的所有数按升序组成的序列,我们要进行一些筛选,每次我们取当前所有数字中从小到大的第奇数位个的数,并将其丢弃。重复这一过程直到最后剩下一个数。请求出最后剩下的数字。析:把所有数放在链表中,每次从里面删除就行了。但是注意,应该从后向前删除。因为如果从前开始删除,数据的index就会发生改变,从而删错。import java.util.LinkedList;import java.ut

2017-03-22 10:01:55 741

原创 进程知识点

进程进程基本特征:动态性、并发性、独立性、异步性和结构特征。 进程结构上包括:程序段、数据段、进程控制块PCB(Process Control Block)组成。PCB是进程存在的唯一标识。系统通过PCB对进程进行控制和管理。 为了方便进程的调度和管理,需将各进程的PCB以适当方法组织起来。常见的有链接方式和索引方式。 链接方式就是形成队列,如就绪队列、阻塞队列。 索引就是将同一状态的进程组

2017-03-15 21:31:17 466

原创 leetcode_3. Longest Substring Without Repeating Characters-没有重复字符的子串

Given a string, find the length of the longest substring without repeating characters.Examples:Given “abcabcbb”, the answer is “abc”, which the length is 3.Given “bbbbb”, the answer is “b”, with the le

2017-03-13 16:27:11 229

原创 分治案例_leetcode_46. Permutations-全排列

Given a collection of distinct numbers, return all possible permutations.For example, [1,2,3] have the following permutations: [ [1,2,3], [1,3,2], [2,1,3], [2,3,1], [3,1,2], [3,2,1]

2017-03-13 10:55:29 261

原创 leet_257. Binary Tree Paths-根到叶子的路径

Given a binary tree, return all root-to-leaf paths.For example, given the following binary tree:1 / \ 2 3 \ 5 All root-to-leaf paths are:[“1->2->5”, “1->3”]析:想办法层次遍历,每个结点都保存从根到它的路径,判断是否叶

2017-03-11 19:36:30 269

原创 leetcode_513.Find Bottom Left Tree Value找树最后一行的最左数

Given a binary tree, find the leftmost value in the last row of the tree.Example 1: Input:2 / \ 1 3Output: 1 Example 2: Input: 1 / \ 2 3 / / \4 5 6 / 7Output: 7析:

2017-03-11 15:38:27 345

原创 leetcode_454. 4Sum II-4个数的和

Given four lists A, B, C, D of integer values, compute how many tuples (i, j, k, l) there are such that A[i] + B[j] + C[k] + D[l] is zero.To make problem a bit easier, all A, B, C, D have same length o

2017-03-11 00:25:42 216

原创 leetcode_15. 3Sum-求数组中三个数和为0

Given an array S of n integers, are there elements a, b, c in S such that a + b + c = 0? Find all unique triplets in the array which gives the sum of zero.Note: The solution set must not contain duplic

2017-03-10 14:18:12 1871

原创 leetcode_437. Path Sum III-二叉树

You are given a binary tree in which each node contains an integer value.Find the number of paths that sum to a given value.The path does not need to start or end at the root or a leaf, but it must go

2017-03-09 20:49:40 233

原创 leetcode_53. 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,-1,2,1] has the

2017-03-08 23:42:33 277

原创 leetcode_326. Power of Three-判断是否3的次方

Given an integer, write a function to determine if it is a power of three.Follow up: Could you do it without using any loop / recursion?判断一个数是否是3的次方?法1:网友神奇方法public boolean isPowerOfThree(int n) {

2017-03-08 20:00:47 567

原创 leetcode_202. Happy Number-找数规律

找规律题的机械方法!Write an algorithm to determine if a number is “happy”.A happy number is a number defined by the following process: Starting with any positive integer, replace the number by the sum of the sq

2017-03-08 16:37:25 370

原创 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 给有序数组,创建 平衡二叉搜索树网友解法:/** * Definition for a binary tree node. * public class TreeNode { * int va

2017-03-08 11:24:30 244

原创 leetcode_169. 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 majority element always

2017-03-07 14:40:41 224

原创 leetcode_404. Sum of Left Leaves-左叶子的和

查找二叉树所有左叶子的和。法1:public int sumOfLeftLeaves(TreeNode root) { if(root == null) return 0; int ans = 0; if(root.left != null) { if(root.left.left == null && root.left.right == null) ans

2017-03-07 09:52:05 234

原创 leetcode_383. Ransom Note-近似子串问题

典型的近似子串问题!Given an arbitrary ransom note string and another string containing letters from all the magazines, write a function that will return true if the ransom note can be constructed from the magaz

2017-03-07 09:01:41 268

原创 leetcode_167 Two Sum II - Input array is sorted

Given an array of integers that is already sorted in ascending order, find two numbers such that they add up to a specific target number.The function twoSum should return indices of the two numbers suc

2017-03-06 21:52:39 242

原创 java创建二叉树及遍历

已知外部提供创建树所需要的数据。方法1:按照从上到下从左到右依次把数据放在对应结点来创建树。 即数组中index处的数据在树中仍然是放在index处,而它的左右子结点分别是 2*index+1 , 2*index+2-- BinaryTree.javapublic class BinaryTree { Node root; int size; // 结点总个数 O

2017-03-05 22:20:17 621 1

原创 leetcode_448 Find All Numbers Disappeared in an Array

Given an array of integers where 1 ≤ a[i] ≤ n (n = size of array), some elements appear twice and others appear once.Find all the elements of [1, n] inclusive that do not appear in this array.Could you

2017-03-04 14:58:29 224

原创 leetcode_136 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 extra me

2017-03-04 00:56:43 503

原创 leetcode_496 Next Greater Element I

You are given two arrays (without duplicates) nums1 and nums2 where nums1’s elements are subset of nums2. Find all the next greater numbers for nums1’s elements in the corresponding places of nums2.The

2017-03-03 21:23:54 180

原创 leetcode_500 Keyboard Row

题目描述: 输入多个字符串,条件:字符串是由键盘上的某一行字母组成的。将满足的字符串输出。public class Solution { public String[] findWords(String[] words) { String[] data = new String[]{"qwertyuiop","asdfghjkl","zxcvbnm"};

2017-03-02 15:19:31 195

转载 java 中几种常用数据结构

参见:http://blog.csdn.net/u010947402/article/details/51878166

2017-03-01 16:01:05 406

原创 14.1 多线程(1)

从线程继承:-- SimpleThread.javapublic class SimpleThread extends Thread { private int countDown = 5; private static int threadCount = 0; public SimpleThread() { // Store the thread name: supe

2017-03-01 10:35:21 213

数据结构(严蔚敏)程序代码

配套严蔚敏数据结构,课本上所有程序算法的代码

2013-11-29

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

TA关注的人

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