- 博客(20)
- 资源 (18)
- 收藏
- 关注
原创 leetcode 190:Reverse Bits
题目: Reverse bits of a given 32 bits unsigned integer.For example, given input 43261596 (represented in binary as 00000010100101000001111010011100), return 964176192 (represented in binary as 001110010
2015-07-09 20:33:57 297
原创 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 00000000
2015-07-09 20:27:58 317
原创 leetcode 70:Climbing Stairs
题目: 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? 分析: 考察动态规划,用户上楼梯,每次可迈1步或2步,现
2015-07-09 01:37:17 325
原创 leetcode 198:House Robber
题目: You are a professional robber planning to rob houses along a street. Each house has a certain amount of money stashed, the only constraint stopping you from robbing each of them is that adjacent h
2015-07-09 01:24:41 345
原创 leetcode 58:Length of Last Word
题目: Given a string s consists of upper/lower-case alphabets and empty space characters ’ ‘, return the length of last word in the string.If the last word does not exist, return 0.Note: A word is defin
2015-07-09 01:09:57 310
原创 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 squares
2015-07-08 13:16:36 386
原创 leetcode 66:plus one
题目: Given a non-negative number represented as an array of digits, plus one to the number.The digits are stored such that the most significant digit is at the head of the list. 分析: 本题是将整数n的每一位存储在数组中
2015-07-08 13:07:01 295
原创 leetcode 225:Implement Stack using Queues
题目: Implement the following operations of a stack using queues.push(x) -- Push element x onto stack.pop() -- Removes the element on top of the stack.top() -- Get the top element.empty() -- Return
2015-07-08 12:56:37 253
原创 leetcode 203:Remove Linked List Elements
题目: Remove all elements from a linked list of integers that have value val.Example Given: 1 –> 2 –> 6 –> 3 –> 4 –> 5 –> 6, val = 6 Return: 1 –> 2 –> 3 –> 4 –> 5 分析: 本题考查链表的操作,要求删除列表元素,只要将指向被删除元素的
2015-07-07 15:20:19 348
原创 leetcode 204:Count Primes
题目: Description:Count the number of prime numbers less than a non-negative number, n. 分析: 本题是要统计0~n的素数个数,这个要根据hint中的提示,利用埃拉托色尼筛法,需要去除0~开根号n的倍数,比如从2开始,去除2*2,2*3,…;最后剩下的就是0~n的素数。 代码:public class coun
2015-07-07 15:11:27 224
原创 leetcode 205:Isomorphic Strings
题目: Given two strings s and t, determine if they are isomorphic.Two strings are isomorphic if the characters in s can be replaced to get t.All occurrences of a character must be replaced with another
2015-07-07 15:01:13 228
原创 leetcode 231:Power of Two
题目: Given an integer, write a function to determine if it is a power of two. 分析: 本题需要判断一个数是否为2的n次方,通过观察2的n次方的十进制和二进制,可以发现一些规律: 1 2 4 8 16 ….1 10 100 1000 10
2015-07-06 17:07:36 232
原创 leetcode 155:Min Stack
题目: Design a stack that supports push, pop, top, and retrieving the minimum element in constant time.push(x) -- Push element x onto stack.pop() -- Removes the element on top of the stack.top() -- G
2015-07-06 16:55:55 248
原创 leetcode 206:Reverse Linked List
题目: Reverse a singly linked list. 分析: 题目考察链表的反转,在这里主要是next指针的调整,利用指向前一个结点的指针before,指向后一个结点的指针followee,从而实现链表的反转。 代码:package Code;public class LinkedList { /** * 链表结点类 * @author Don
2015-07-06 16:48:25 233
原创 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 elemen
2015-07-05 12:13:17 238
原创 leetcode 219:Contains Duplicate II
题目: Given an array of integers and an integer k, find out whether there there are two distinct indices i and j in the array such that nums[i] = nums[j] and the difference between i and j is at most k.
2015-07-05 11:12:54 358
原创 leetcode 223:Rectangle Area
题目: Find the total area covered by two rectilinear rectangles in a 2D plane.Each rectangle is defined by its bottom left corner and top right corner as shown in the figure. Rectangle Area Assume tha
2015-07-05 10:50:39 426
原创 leetcode 226 :Invert Binary Tree
题目: Invert a binary tree.4 / \ 2 7 / \ / \ 1 3 6 9to4 / \ 7 2 / \ / \ 9 6 3 1 分析: 本题是对二叉树的操作,题目要求将二叉树反转,可以有递归和非递归两种实现方法,在编写测试用例的时候,需要构建二叉树和遍历二叉树,所以在代码中一致列
2015-07-04 11:41:07 521
原创 leetcode 228:Summary Ranges
leetcode 228:Summary Ranges题目: Given a sorted integer array without duplicates, return the summary of its ranges.For example, given [0,1,2,4,5,7], return [“0->2”,”4->5”,”7”]. 分析: 这道题是对数组的操作,给定一
2015-07-04 11:29:19 292
原创 leetCode 6:ZigZag Conversion
leetCode 6:ZigZag Conversion题目: The string “PAYPALISHIRING” is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a fixed font for better legib
2015-07-04 10:18:52 354
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人