
LeetCode
石楠花
菜鸟java从业者。
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
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 · 306 阅读 · 0 评论 -
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 · 340 阅读 · 0 评论 -
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 · 310 阅读 · 0 评论 -
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 · 311 阅读 · 0 评论 -
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 · 332 阅读 · 0 评论 -
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 · 358 阅读 · 0 评论 -
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 · 392 阅读 · 0 评论 -
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 · 321 阅读 · 0 评论 -
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 · 356 阅读 · 0 评论 -
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 · 310 阅读 · 0 评论