leetcode
roamer_nuptgczx
这个作者很懒,什么都没留下…
展开
-
Leetcode - Reverse Linked List
Reverse a singly linked list.HintA linked list can be reversed either iteratively or recursively. Could you implement both?Java Code迭代递归原创 2016-05-01 18:15:42 · 477 阅读 · 0 评论 -
Leetcode - Add Digits
Given a non-negative integer num, repeatedly add all its digits until the result has only one digit. ExampleGiven num = 38, the process is like: 3 + 8 = 11, 1 + 1 = 2. Since 2 has only one digi原创 2016-05-05 16:14:46 · 280 阅读 · 0 评论 -
Leetcode - Valid Anagram
Given two strings s and t, write a function to determine if t is an anagram of s.Examples = “anagram”, t = “nagaram”, return true. s = “rat”, t = “car”, return false. NoteYou may assume the st原创 2016-05-05 14:43:41 · 332 阅读 · 0 评论 -
Leetcode - Lowest Common Ancestor of a Binary Search Tree
Given a binary search tree (BST), find the lowest common ancestor (LCA) of two given nodes in the BST. According to the definition of LCA on Wikipedia: “The lowest common ancestor is defined b原创 2016-05-05 14:35:40 · 258 阅读 · 0 评论 -
Leetcode - Power of Three
Given an integer, write a function to determine if it is a power of three. Follow upCould you do it without using any loop / recursion? Java Code/*** 版本一:判断因子法* 先找到整数范围内最大的3的幂maxNum,再判断n是否能被m原创 2016-05-05 10:20:31 · 270 阅读 · 0 评论 -
Leetcode - Reverse Integer
Reverse digits of an integer.Example1: x = 123, return 321 Example2: x = -123, return -321 Have you thought about this?Here are some good questions to ask before coding. Bonus points for you i原创 2016-03-28 22:40:56 · 461 阅读 · 0 评论 -
Leetcode - 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 anoth原创 2016-05-04 21:57:48 · 489 阅读 · 0 评论 -
Leetcode - Invert Binary Tree
Invert a binary tree. This problem was inspired by this original tweet by Max Howell: Google: 90% of our engineers use the software you wrote (Homebrew), but you can’t invert a binary tree on a whiteboard so原创 2016-05-04 22:27:47 · 357 阅读 · 0 评论 -
Leetcode - Contains Duplicate II
Given an array of integers and an integer k, find out whether 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. Ja原创 2016-05-04 22:09:29 · 293 阅读 · 0 评论 -
Leetcode - 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 ele原创 2016-05-04 22:06:29 · 318 阅读 · 0 评论 -
Leetcode - 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 squa原创 2016-05-04 21:51:50 · 376 阅读 · 0 评论 -
Leetcode - 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 adjacen原创 2016-05-04 21:42:28 · 303 阅读 · 0 评论 -
Leetcode - Move Zeroes
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 y原创 2016-05-05 18:18:32 · 362 阅读 · 0 评论 -
Leetcode - Bulls and Cows
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 h原创 2016-05-05 18:52:11 · 460 阅读 · 0 评论 -
Leetcode - TwoSum
Given an array of integers, return indices of the two numbers such that they add up to a specific target.You may assume that each input would have exactly one solution.原创 2016-03-28 13:43:15 · 532 阅读 · 0 评论 -
Leetcode - 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?原创 2016-04-18 13:46:38 · 326 阅读 · 0 评论 -
Leetcode - Power of Two
Given an integer, write a function to determine if it is a power of two. Java Code//版本一:通过整数二进制位中1的个数来判断如果所有二进制位上只有一个1,则n是2的幂。原创 2016-05-05 10:12:27 · 260 阅读 · 0 评论 -
Leetcode - 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.NoteA word is defi原创 2016-05-05 20:55:58 · 418 阅读 · 0 评论 -
Leetcode - Word Pattern
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 in pattern and a non-empty word in str.Exa原创 2016-05-05 18:24:24 · 365 阅读 · 0 评论 -
Leetcode - Binary Tree Paths
Given a binary tree, return all root-to-leaf paths. For example, given the following binary tree:All root-to-leaf paths are: ["1->2->5", "1->3"]Java Code原创 2016-05-05 14:49:05 · 280 阅读 · 0 评论 -
Leetcode - 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原创 2016-05-05 16:19:57 · 326 阅读 · 0 评论 -
Leetcode - 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.Assume that the total are原创 2016-05-04 22:14:01 · 421 阅读 · 0 评论 -
Leetcode - 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原创 2016-05-05 18:32:57 · 453 阅读 · 0 评论 -
Leetcode - Reverse Vowels of a String
Write a function that takes a string as input and reverse only the vowels of a string.ExampleGiven s = “hello”, return “holle”. Given s = “leetcode”, return “leotcede”. Java Codepublic Strin原创 2016-05-05 19:10:32 · 285 阅读 · 0 评论 -
Leetcode - Longest Increasing Subsequence
Given an unsorted array of integers, find the length of longest increasing subsequence. For example, Given [10, 9, 2, 5, 3, 7, 101, 18], The longest increasing subsequence is [2, 3, 7, 101]原创 2016-05-05 19:01:59 · 338 阅读 · 0 评论 -
Leetcode - 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 001110原创 2016-05-04 21:37:30 · 435 阅读 · 0 评论 -
Leetcode - 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]. NoteTry to come up as many solutions as you can原创 2016-05-04 19:38:32 · 363 阅读 · 0 评论 -
Leetcode - Remove Element
Given an array and a value, remove all instances of that value in place and return the new length. Do not allocate extra space for another array, you must do this in place with constant memor原创 2016-04-09 15:01:51 · 385 阅读 · 0 评论 -
Leetcode - Remove Duplicates from Sorted Array
Given a sorted array, remove the duplicates in place such that each element appear only once and return the new length.Do not allocate extra space for another array, you must do this in place w原创 2016-04-09 21:48:28 · 305 阅读 · 0 评论 -
Leetcode - Valid Sudoku
Determine if a Sudoku is valid, according to: Sudoku Puzzles - The Rules.The Sudoku board could be partially filled, where empty cells are filled with the character ‘.’. 简述一下检查的规则: 1. 每一行中数字1原创 2016-04-10 15:13:04 · 315 阅读 · 0 评论 -
Leetcode - Count and Say
The count-and-say sequence is the sequence of integers beginning as follows: 1, 11, 21, 1211, 111221, … 1 is read off as “one 1” or 11. 11 is read off as “two 1s” or 21. 21 is read off as “o原创 2016-04-10 17:00:07 · 341 阅读 · 0 评论 -
Leetcode - Merge Sorted Array
Given two sorted integer arrays nums1 and nums2, merge nums2 into nums1 as one sorted array.NoteYou may assume that nums1 has enough space (size that is greater or equal to m + n) to hold addit原创 2016-04-18 16:49:56 · 225 阅读 · 0 评论 -
Leetcode - Same Tree
Given two binary trees, write a function to check if they are equal or not. Two binary trees are considered equal if they are structurally identical and the nodes have the same value.Java Code原创 2016-04-18 18:53:47 · 301 阅读 · 0 评论 -
Leetcode - Maximum Depth of Binary Tree
Given a binary tree, find its maximum depth.The maximum depth is the number of nodes along the longest path from the root node down to the farthest leaf node.Java Codepublic class TreeNode原创 2016-04-19 17:20:36 · 274 阅读 · 0 评论 -
Leetcode - Minimum Depth of Binary Tree
Given a binary tree, find its minimum depth.The minimum depth is the number of nodes along the shortest path from the root node down to the nearest leaf node.Java Codepublic class TreeNode {原创 2016-04-19 21:11:17 · 330 阅读 · 0 评论 -
Leetcode - Balanced Binary Tree
Given a binary tree, determine if it is height-balanced. For this problem, a height-balanced binary tree is defined as a binary tree in which the depth of the two subtrees of every node never d原创 2016-04-19 22:40:11 · 312 阅读 · 0 评论 -
Leetcode - Path Sum
Given a binary tree and a sum, determine if the tree has a root-to-leaf path such that adding up all the values along the path equals the given sum. For example:Given the below binary tree an原创 2016-04-20 15:16:25 · 314 阅读 · 0 评论 -
Leetcode - Pascal's Triangle
Given numRows, generate the first numRows of Pascal’s triangle.For example, given numRows = 5,[ [1], [1,1], [1,2,1], [1,3,3,1], [1,4,6,4,1]]Java Codepublic List<List<Integer>> g原创 2016-04-20 17:17:42 · 242 阅读 · 0 评论 -
Leetcode - Palindrome Number
Determine whether an integer is a palindrome. Do this without extra space.Some hints:Could negative integers be palindromes? (ie, -1)If you are thinking of converting the integer to string, not原创 2016-03-30 13:41:21 · 390 阅读 · 0 评论 -
Leetcode - Median of Two Sorted Arrays
There are two sorted arrays nums1 and nums2 of size m and n respectively. Find the median of the two sorted arrays. The overall run time complexity should be O(log (m+n)).原创 2016-03-29 22:42:23 · 384 阅读 · 0 评论