- 博客(32)
- 资源 (1)
- 收藏
- 关注
原创 Excel Sheet Column Title 把整数转换为大写字母的组合
Given a positive integer, return its corresponding column title as appear in an Excel sheet.For example: 1 -> A 2 -> B 3 -> C ... 26 -> Z 27 -> AA 28 -> AB /*String
2015-12-30 22:20:35 312
原创 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 alw
2015-12-30 20:57:05 323
原创 Excel Sheet Column Number 把大写字符串转换为整数
Related to question Excel Sheet Column TitleGiven a column title as appear in an Excel sheet, return its corresponding column number.For example: A -> 1 B -> 2 C -> 3 ... Z
2015-12-30 19:47:34 337
原创 Factorial Trailing Zeroes 阶乘的后边有几个0
Given an integer n, return the number of trailing zeroes in n!.Note: Your solution should be in logarithmic time complexity.//含因子5为几个就是几个0,像25*4=100,所以25含有2个5,http://www.zhihu.com/question/3
2015-12-30 18:07:16 248
原创 Rotate Array 数组以某个元素为节点进行前后反转
Rotate an array of n elements to the right by k steps.For example, with n = 7 and k = 3, the array [1,2,3,4,5,6,7] is rotated to[5,6,7,1,2,3,4]. Note:Try to come up as many solutions as you ca
2015-12-30 16:10:08 242
转载 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 as0011100101
2015-12-29 23:06:28 630
转载 Number of 1 Bits 1的位数
Write a function that takes an unsigned integer and returns the number of ’1' bits it has (also known as theHamming weight).For example, the 32-bit integer ’11' has binary representation 000000000
2015-12-29 22:30:10 278
转载 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 house
2015-12-29 15:32:20 670
原创 Happy Number 判断一个整数的各个位数的平方的和到最后是不是1
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 o
2015-12-28 22:21:29 608
原创 Remove Linked List Elements 删除单链表里边指定的元素
Remove all elements from a linked list of integers that have value val.ExampleGiven: 1 --> 2 --> 6 --> 3 --> 4 --> 5 --> 6, val = 6Return: 1 --> 2 --> 3 --> 4 --> 5public class Solution {
2015-12-28 16:52:06 420
原创 Count Primes 小于n的非负整数里边素数的个数
Description:Count the number of prime numbers less than a non-negative number, n.1不是素数,素数是指除了1和它本身之外没有其他的约数/*public class Solution { //超时,时间复杂度超了 public int countPrimes(int n) {
2015-12-28 15:52:13 560
原创 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 gett.All occurrences of a character must be replaced with another
2015-12-28 09:29:33 270
原创 Reverse Linked List 单链表反转
/** * Definition for singly-linked list. * public class ListNode { * int val; * ListNode next; * ListNode(int x) { val = x; } * } */ public class Solution { pu
2015-12-27 21:08:11 236
转载 Contains Duplicate II 找出数组中是否有重复元素,长度小于k
Given an array of integers and an integer k, find out whether there are two distinct indicesi and j in the array such that nums[i] = nums[j] and the difference betweeni and j is at most k.出处:htt
2015-12-27 19:24:45 276
转载 Rectangle Area 两个矩形的面积
出处http://www.thinksaas.cn/group/topic/395502/Find the total area covered by two rectilinear rectangles in a2D plane.Each rectangle is defined by its bottom left corner and top right corner a
2015-12-27 16:15:36 361
原创 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 whet
2015-12-27 13:44:38 432
原创 Invert Binary Tree 二叉树反转
Invert a binary tree. 4 / \ 2 7 / \ / \1 3 6 9to 4 / \ 7 2 / \ / \9 6 3 1/** * Definition for a binary tree node. * public class TreeNod
2015-12-26 21:48:59 240
转载 Summary Ranges 有序数组找出连续的子数组并且输出
出处:http://blog.csdn.net/xudli/article/details/46645087Given 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",
2015-12-25 22:27:53 318
转载 Power of Two 判断一个数是不是2的幂
Given an integer, write a function to determine if it is a power of two.public class Solution { public boolean isPowerOfTwo(int n) { if(n==0) return false;
2015-12-25 19:37:44 444
转载 Implement Queue using Stacks 用俩栈实现队列
Implement the following operations of a queue using stacks.push(x) -- Push element x to the back of queue.pop() -- Removes the element from in front of queue.peek() -- Get the front element.empty(
2015-12-25 15:58:45 227
原创 Palindrome Linked List 判断一个链表是不是回文串
Given a singly linked list, determine if it is a palindrome.Follow up:Could you do it in O(n) time and O(1) space?public class Solution { public boolean isPalindrome(ListNode head) {
2015-12-24 20:07:14 365
转载 Lowest Common Ancestor of a Binary Search Tree
转载出处 http://blog.csdn.net/xudli/article/details/46838747Given a binary search tree (BST), find the lowest common ancestor (LCA) of two given nodes in the BST.According to the definition of
2015-12-24 15:29:04 416
转载 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 assum
2015-12-23 22:06:15 418
转载 Binary Tree Paths return all root-to-leaf paths.
Given a binary tree, return all root-to-leaf paths.For example, given the following binary tree: 1 / \2 3 \ 5All root-to-leaf paths are:["1->2->5", "1->3"]转载出处http://se
2015-12-23 17:17:58 326
原创 Range Sum Query - Immutable
Given an integer array nums, find the sum of the elements between indicesi and j (i ≤ j), inclusive.Example:Given nums = [-2, 0, 3, -5, 2, -1]sumRange(0, 2) -> 1sumRange(2, 5) -> -1sumRang
2015-12-22 11:26:38 235
转载 Bulls and Cows 1807 7810 return "1A3B"
You are playing the following Bulls and Cows game with your friend: You write down a number and ask your friend to guess what the number is. Each time your friend makes a guess, you provide a hint t
2015-12-22 11:16:01 327
原创 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
2015-12-22 11:13:22 248
原创 Word Pattern pattern = "abba", str = "dog cat cat dog" should return true
Given a pattern and a string str, find if str follows the same pattern.Here follow means a full match, such that there is a bijection between a letter inpattern and a non-empty word in str.Examp
2015-12-22 11:09:32 947
原创 Move Zeroes 去除0且按照原来顺序返回
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 your fu
2015-12-22 11:03:26 273
原创 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
2015-12-22 10:57:01 236
原创 Ugly Number whose prime factors only include 2, 3, 5. For example, 6, 8 are ugly while 14 is not
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 since i
2015-12-22 10:50:44 794
原创 Add Digits 38 3 + 8 = 11 1 + 1 = 2
258. Add DigitsGiven a non-negative integer num, repeatedly add all its digits until the result has only one digit.For example:Given num = 38, the process is like: 3 + 8 = 11, 1 + 1 =
2015-12-22 09:49:48 385
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人