- 博客(38)
- 收藏
- 关注
原创 记录一下CountDownLatch 和 CyclicBarrier 的使用例子
之前的面试有被提到过java.util.concurrent中解决并发的问题。看Thinking in Java 学习一下其中一些构件的使用。本文记录关于CountDownLatch 和 CyclicBarrier 使用的小例子。CountDownLatch 典型用法就是将一个程序分成n个相互独立的可解决的任务(锁存器)public class CountDownLatchDem
2016-08-18 21:02:24 457
翻译 Animation and Graphics partⅡ Property Animation
本文是对Android动画API的官方资料的翻译。原文连接:https://developer.android.com/guide/topics/graphics/prop-animation.html以下正文开始:属性动画属性动画系统是一个强大的框架,几乎可以使任何对象产生动画。你可以随着时间改变任意的对象属性来定义动画效果,不管该属性是否显示在屏幕上。属性动画在指定的时间长度改
2016-07-07 14:13:17 1261 1
翻译 Animation and Graphics partⅠ Overview
对Android动画API的官方资料的翻译。原文链接:https://developer.android.com/guide/topics/graphics/overview.html以下正文开始:动画和图形概述Android提供了很多功能强大的API,将动画应用于 UI 元素和绘制自定义 2D 或者 3D 图形方面。动画(Animation)Android提供了两种动画系
2016-07-04 15:52:24 488
原创 LeetCode 202. Happy Number & 263. Ugly Number
202. Happy NumberWrite 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
2016-07-03 22:01:03 631
原创 LeetCode 371. Sum of Two Integers
Calculate the sum of two integers a and b, but you are not allowed to use the operator + and -.Example:Given a = 1 and b = 2, return 3.分析:不使用“+”“-”等符号来进行加法运算。一般情况下是可以用位运算来解决。先来看一位二进制加法1
2016-06-30 11:46:26 557
原创 LeetCode 141. 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?分析:可以将结点存入数组中,此方法需要额外的空间,也可以用双指针,快慢指针同时向前跑,如果跑到结尾,就没环,如果被套圈,证明有环。代码:/** * Def
2016-03-12 21:51:28 353
原创 LeetCode 96. 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 1 \
2016-03-07 18:33:22 327
原创 LeetCode 278. First Bad Version
You are a product manager and currently leading a team to develop a new product. Unfortunately, the latest version of your product fails the quality check. Since each version is developed based on the
2016-03-07 15:23:14 360
原创 LeetCode 35. 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 the array.
2016-03-07 10:42:40 521
原创 LeetCode 328. Odd Even Linked List
Given a singly linked list, group all odd nodes together followed by the even nodes. Please note here we are talking about the node number and not the value in the nodes.You should try to do it in
2016-03-07 09:26:33 350
原创 LeetCode 231. Power of Two & 326. Power of Three
Given an integer, write a function to determine if it is a power of two or three.分析:判断一个数是否是2的幂(另一题是3的幂)直观的解决办法就是循环除 2 或者 3 来判断,另外一种不需要循环的方式就是用对数和幂指数的数学方法来运算。另外,由于数据可以用二进制表示,那么 2 的幂可以通过位运算来判断。
2016-03-05 12:58:53 360
原创 LeetCode 191. 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 000000
2016-03-05 10:27:50 362
原创 Java排序算法总结之(五)—— 基数排序
排序方法可以分为两种:内部排序 和 外部排序内部排序的方法很多,常用的大致可以分为:插入排序(直接插入排序、折半插入排序、希尔排序)交换排序(冒泡排序、快速排序)选择排序(简单选择排序、堆排序)归并排序基数排序基数排序基本思想:与之前各种排序算法需要比较和移动不同,基数排序不需要比较,只通过关键字分类来完成排序。比如一个序列有 n 个数据 {R1,R2,R3,…,Rn}
2016-03-03 14:33:40 685
原创 Java排序算法总结之(四)——归并排序
排序方法可以分为两种:内部排序 和 外部排序内部排序的方法很多,常用的大致可以分为:插入排序(直接插入排序、折半插入排序、希尔排序)交换排序(冒泡排序、快速排序)选择排序(简单选择排序、堆排序)归并排序基数排序归并排序:基本思想:将两个或两个以上的有序表组合成一个新的有序表。归并的思路很好理解,有下面的示例:示例: Java代码:pu
2016-03-03 11:41:59 1200
原创 Java排序算法总结之(三)——选择排序(简单选择排序、堆排序)
排序方法可以分为两种:内部排序 和 外部排序内部排序的方法很多,常用的大致可以分为:插入排序(直接插入排序、折半插入排序、希尔排序)交换排序(冒泡排序、快速排序)选择排序(简单选择排序、堆排序)归并排序基数排序选择排序1.简单选择排序基本思想:对数列的 n 个元素进行比较,选出最小(或者最大)的元素,与起始位置的值交换,再从余下的数据中找到最小(最大)值,放在已排序部分
2016-03-02 15:56:58 904
原创 Java排序算法总结之(二)——基于交换排序(冒泡排序、快速排序)
交换排序1.冒泡排序基本操作:比较相邻的元素。如果第一个比第二个大,就交换他们两个。对每一对相邻元素作同样的工作,从开始第一对到结尾的最后一对。这步做完后,最后的元素会是最大的数。针对所有的元素重复以上的步骤,除了最后一个。持续每次对越来越少的元素重复上面的步骤,直到没有任何一对数字需要比较。冒泡排序简介易懂,是入门的程序设计算法之一。Java代码:publ
2016-03-01 20:10:22 615
原创 Java排序算法总结之(一)——插入排序(直接插入排序、折半插入排序、希尔排序)
排序方法可以分为两种:内部排序 和 外部排序内部排序的方法很多,大致可以分为:插入排序(直接插入排序、折半插入排序、希尔排序)快速排序(基于交换的一种排序方式,最常见的是 冒泡排序)选择排序(简单选择排序、堆排序)归并排序基数排序一、直接插入排序基本操作:将一个数据插入到已排好序的有序表中,从而得到一个新的、长度加1的有序表。代码:package com.yan
2016-02-29 22:51:21 816
原创 LeetCode 235. Lowest Common Ancestor of a Binary Search Tree
Given a binary search tree (BST), find the lowest common ancestor (LCA) of two given nodes in the BST.According to the definition of LCA on Wikipedia: “The lowest common ancestor is defined betw
2016-02-28 11:48:30 404
原创 LeetCode 206. Reverse Linked List
Reverse a singly linked list.Hint:A linked list can be reversed either iteratively or recursively. Could you implement both?分析:单链表翻转问题:迭代和递归两种做法代码一:递归/** * Definition for singly-linked li
2016-02-25 22:17:03 303
原创 LeetCode 318. Maximum Product of Word Lengths
Given a string array words, find the maximum value of length(word[i]) * length(word[j]) where the two words do not share common letters. You may assume that each word will contain only lower case le
2016-02-24 22:48:45 291
原创 LeetCode 94. 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 solutio
2016-02-22 19:04:49 239
原创 LeetCode 144. Binary Tree Preorder Traversal
LeetCode,Binary Tree Preorder Traversal,迭代,两种形式,堆栈
2016-02-22 00:07:07 269
原创 LeetCode 268. Missing Number
Given an array containing n distinct numbers taken from 0, 1, 2, ..., n, find the one that is missing from the array.For example,Given nums = [0, 1, 3] return 2.Note:Your algorithm shoul
2016-02-20 16:10:24 296
原创 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
2016-02-18 14:50:32 282
原创 LeetCode 171. Excel Sheet Column Number & 168. Excel Sheet Column Title
LeetCode 171. Excel Sheet Column Number & 168. Excel Sheet Column Title
2016-02-18 00:21:39 386
原创 LeetCode 217. Contains Duplicate
Given an array of integers, find if the array contains any duplicates. Your function should return true if any value appears at least twice in the array, and it should return false if every element
2016-02-17 14:11:13 271
原创 LeetCode 242. Valid Anagram
Given two strings s and t, write a function to determine if t is an anagram of s.For example,s = "anagram", t = "nagaram", return true.s = "rat", t = "car", return false.Note:You may ass
2016-02-16 23:21:45 378
原创 LeetCode 238. Product of Array Except Self
Given an array of n integers where n > 1, nums, return an array output such that output[i] is equal to the product of all the elements of nums except nums[i].Solve it without division and in O
2016-02-16 15:02:44 306
原创 LeetCode 136.137. 260.Single Number ⅠII III
LeetCode 136.137. 260.Single Number ⅠII III
2016-02-15 23:53:09 416
原创 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.分析:二叉树的问题,
2016-02-14 16:14:59 349
原创 LeetCode 283. Move Zeroes
Given an array nums, write a function to move all 0's to the end of it while maintaining the relative order of the non-zero elements.For example, given nums = [0, 1, 0, 3, 12], after calling you
2016-02-13 20:36:07 249
原创 LeetCode 226. Invert Binary Tree
Invert a binary tree. 4 / \ 2 7 / \ / \1 3 6 9to 4 / \ 7 2 / \ / \9 6 3 1分析:又是二叉树的问题,很多二叉树的问题可以用递归算法来解决。先判断当前结点是否为空,此为递归的出口;接下来交换左孩子和右孩子的位置,分别以左孩子
2016-02-12 20:35:09 302
原创 LeetCode 292. Nim Game
You are playing the following Nim Game with your friend: There is a heap of stones on the table, each time one of you take turns to remove 1 to 3 stones. The one who removes the last stone will be the
2016-02-12 15:10:24 228
原创 LeetCode 237. Delete Node in a Linked List
Write a function to delete a node (except the tail) in a singly linked list, given only access to that node.Supposed the linked list is 1 -> 2 -> 3 -> 4 and you are given the third node with value
2016-02-11 22:25:05 256
原创 LeetCode 104. Maximum Depth of Binary Tree && Minimum Depth of Binary
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.本题目是简单的二叉树深度问题,二叉树是每个节点最多有两个子树的树结构
2016-02-11 16:34:57 255
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人