- 博客(11)
- 收藏
- 关注
原创 【Leetcode】:9. Palindrome Number 问题 in JAVA
Determine whether an integer is a palindrome. Do this without extra space.题目要求判断一个数是否是回文数,例如123321,9889就是回文数这道题要求不能使用额外的空间,想了很久都不知道怎么做,只有网上查了下,原来创建一个变量不叫使用额外空间。。。public class Solution {
2016-05-24 21:47:14 734
原创 Java中的报错:Cannot make a static reference to the non-static field
在下面这段代码中会报错System.out.println(s1);Cannot make a static reference to the non-static field s1只要把s1的申明加上static,就不会报错了,这有点让奇怪,看报错是说不能在非静态域进行静态引用,查询了一下原因,由于该方法是静态方法,s1变量非静态变量,所以s1是依赖于对象的存在而存在的,也就
2016-05-24 12:22:45 11776
原创 【Leetcode】:116. Populating Next Right Pointers in Each Node 问题 in JAVA
Given a binary tree struct TreeLinkNode { TreeLinkNode *left; TreeLinkNode *right; TreeLinkNode *next; }Populate each next pointer to point to its next right node. If there i
2016-05-11 13:03:48 557
原创 【Leetcode】:89. Gray Code 问题 in JAVA
The gray code is a binary numeral system where two successive values differ in only one bit.Given a non-negative integer n representing the total number of bits in the code, print the sequence of
2016-05-10 14:04:39 1279
原创 【Leetcode】:326. Power of Three 问题 in 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 sinc
2016-05-09 12:17:41 388
原创 【Leetcode】:326. Power of Three 问题 in JAVA
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?题目要求不能使用循环或者递归,这里需要用到数学的一点小技巧。首先如果n《=0,那么一定返货false如
2016-05-07 15:46:03 1180
原创 【Leetcode】:Best Time to Buy and Sell Stock with Cooldown 问题 in JAVA
这是一道股票买卖的问题,加了一个特殊条件,卖出以后要隔一天才能交易,这道题花了我好久的时间,期间参考了“http://www.cnblogs.com/grandyang/p/4997417.html”
2016-05-05 23:05:01 475
原创 【Leetcode】:70. Climbing Stairs 问题 in Go语言
这道题的难度定义为Easy,知道思路解决起来确实简单,但是要分析出思路并不容易。题目要求出有多少种爬梯子的办法,并且规定每次只能爬一级阶梯或者两级解题,如此一来我们可以知道最后一步不是爬了一级阶梯就是爬了两级解题,那么问题就可以被分解了。爬n级阶梯的种数 = 最后一步爬一级阶梯种数+最后一步趴两级阶梯的种数 = 爬n-1级阶梯的种数 + 爬n-2级阶梯的种数
2016-05-05 19:36:40 646
原创 【Leetcode】:22. Generate Parentheses 问题 in Go语言
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:"((()))", "(()())", "(())()", "()(())", "()()
2016-05-02 22:33:35 653
原创 【Leetcode】:108. Convert Sorted Array to Binary Search Tree 问题 in JAVA
题目:Given an array where elements are sorted in ascending order, convert it to a height balanced BST.题目要求按照给定的已经排序的数组,生成一个平衡的二叉树用递归的方法来做的话,这道题还是很简单的,只要记住,为了保持平衡,每一个节点的val在它所有子节点的val中排中间大。/** *
2016-05-02 20:13:49 729
原创 【Leetcode】:337. House Robber III 问题 in JAVA
题目:The thief has found himself a new place for his thievery again. There is only one entrance to this area, called the "root." Besides the root, each house has one and only one parent house. Aft
2016-05-01 16:03:09 348
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人