- 博客(12)
- 收藏
- 关注
原创 JAVA 1.8 新特性学习(2) lambda表达式
public class NameExample { public static void main(String[] args) { Names nameIns
2016-04-16 14:47:46
376
原创 JAVA 1.8 新特性学习(1) 接口的默认方法
java 1.8中,现在接口也可以定义实现了的方法了。用default定义方法就可以了。具体的例子可以看下面的代码:public class Test { public static void main(String[] args) { Animal bird = new Bird(); bird.breathe(); bird.move
2016-04-16 13:37:09
889
原创 LeetCode Best Time to Buy and Sell Stock JAVA
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 the stock),
2016-04-13 14:20:16
292
原创 LeetCode Power of Three JAVA
Given an integer, write a function to determine if it is a power of three.public class Solution { public boolean isPowerOfThree(int n) { while (n >= 3){ if(n%3 == 0){
2016-04-13 11:22:31
345
原创 LeetCode Power of Two JAVA
Given an integer, write a function to determine if it is a power of two.public class Solution { public boolean isPowerOfTwo(int n) { int sum = 0; if(n <= 0){ return f
2016-04-12 20:42:35
302
原创 LeetCode Ugly Number JAVA
Write a program to check whether a given number is an ugly number.Ugly numbers are positive numbers whose prime factors only include 2, 3, 5. For example, 6, 8 are ugly while 14 is not ugly si
2016-04-11 17:13:39
304
原创 LeetCode Climbing Stairs JAVA
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?简单分析一下,如果我第一步走了一步,那么剩下来就是f(n
2016-04-11 16:03:27
326
原创 LeetCode Number of 1 Bits JAVA
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-04-09 16:36:11
300
原创 LeetCode Contains Duplicate JAVA
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-04-09 14:37:25
317
原创 LeetCode Valid Anagram JAVA
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 a
2016-04-09 14:10:35
383
原创 LeetCode Majority Element JAVA
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-04-09 14:03:05
352
原创 LeetCode Excel Sheet Column Number JAVA
写的比较挫,先是判断一下,如果是String只有一个单词的话,就比较简单,直接返回这个单词对应的值就行了。如果有多个单词的话,就先把第一个到倒数第二个的所有和都加起来,再加上最后一位的值就OK了。public class Solution { public int titleToNumber(String s) { int sum = 0; char[]
2016-04-09 11:15:08
314
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人