
实实在在刷点题
文章平均质量分 67
NOadu
这个作者很懒,什么都没留下…
展开
-
LeetCode-338. Counting Bits (Java)
Given a non negative integer number num. For every numbers i in the range 0 ≤ i ≤ num calculate the number of 1's in their binary representation and return them as an array.Example:For num = 5原创 2017-07-24 21:18:18 · 561 阅读 · 0 评论 -
LeetCode-101. Symmetric Tree(Java)
Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center).For example, this binary tree [1,2,2,3,4,4,3] is symmetric: 1 / \ 2 2 / \ / \3 4 4 3原创 2017-07-14 11:43:44 · 452 阅读 · 0 评论 -
LeetCode-537. Complex Number Multiplication
Given two strings representing two complex numbers.You need to return a string representing their multiplication. Note i2 = -1 according to the definition.Example 1:Input: "1+1i", "1+1i"O原创 2017-06-14 10:31:38 · 563 阅读 · 0 评论 -
LeetCode-242. 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.--------------------原创 2017-06-26 12:16:03 · 381 阅读 · 0 评论 -
LeetCode-415. Add Strings (Java)
Given two non-negative integers num1 and num2 represented as string, return the sum of num1 and num2.Note:The length of both num1 and num2 is Both num1 and num2 contains only digits 0-9.原创 2017-07-04 23:25:30 · 390 阅读 · 0 评论 -
LeetCode-169. 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原创 2017-06-25 16:24:42 · 458 阅读 · 0 评论 -
LeetCode-237. Delete Node in a Linked List(Java)
Write a function to delete a node (except the tail) in a singly linked list, given only access to that node.Supposed the linked list is 1 -> 2 -> 3 -> 4 and you are given the third node with value原创 2017-06-25 12:40:25 · 427 阅读 · 0 评论 -
LeetCode-27. Remove Element(Java)
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 memory.原创 2017-07-13 15:00:29 · 353 阅读 · 0 评论 -
LeetCode-100. Same Tree (Java)
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.----------原创 2017-06-25 11:47:39 · 473 阅读 · 0 评论 -
LeetCode-387. First Unique Character in a String (Java)
Given a string, find the first non-repeating character in it and return it's index. If it doesn't exist, return -1.Examples:s = "leetcode"return 0.s = "loveleetcode",return 2.Note: You ma原创 2017-06-25 09:58:48 · 540 阅读 · 0 评论 -
LeetCode-235. Lowest Common Ancestor of a Binary Search Tree (Java)
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 betwee原创 2017-07-13 12:44:24 · 392 阅读 · 0 评论 -
LeetCode-171. Excel Sheet Column Number (Java)
Given a column title as appear in an Excel sheet, return its corresponding column number.For example: A -> 1 B -> 2 C -> 3 ... Z -> 26 AA -> 27 AB -> 28 ------------原创 2017-06-24 09:20:45 · 577 阅读 · 0 评论 -
LeetCode-108. Convert Sorted Array to Binary Search Tree(Java)
Given an array where elements are sorted in ascending order, convert it to a height balanced BST.-----------------------------------------------------------------------------------------------------原创 2017-07-03 10:45:47 · 398 阅读 · 0 评论 -
LeetCode-389. Find the Difference (Java)
参考地址:http://www.cnblogs.com/styshoo/p/5922397.htmlGiven two strings s and t which consist of only lowercase letters.String t is generated by random shuffling string s and then add one more l转载 2017-06-12 11:14:20 · 418 阅读 · 0 评论 -
LeetCode-198. House Robber (Java)
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原创 2017-07-14 10:02:05 · 369 阅读 · 0 评论 -
LeetCode-409. Longest Palindrome (Java)
Given a string which consists of lowercase or uppercase letters, find the length of the longest palindromes that can be built with those letters.This is case sensitive, for example "Aa" is not con原创 2017-06-27 14:45:49 · 389 阅读 · 0 评论 -
LeetCode-463. Island Perimeter (Java)
You are given a map in form of a two-dimensional integer grid where 1 represents land and 0 represents water. Grid cells are connected horizontally/vertically (not diagonally). The grid is completely转载 2017-06-07 09:17:30 · 475 阅读 · 0 评论 -
LeetCode-257. Binary Tree Paths (Java)
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"]-------原创 2017-07-19 20:38:18 · 396 阅读 · 0 评论 -
LeetCode-367. Valid Perfect Square (Java)
Given a positive integer num, write a function which returns True if num is a perfect square else False.Note: Do not use any built-in library function such as sqrt.Example 1:Input: 16原创 2017-07-19 17:57:27 · 473 阅读 · 0 评论 -
LeetCode-501. Find Mode in Binary Search Tree(Java)
Given a binary search tree (BST) with duplicates, find all the mode(s) (the most frequently occurred element) in the given BST.Assume a BST is defined as follows:The left subtree of a node c原创 2017-07-19 16:52:19 · 986 阅读 · 0 评论 -
LeetCode-70. 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?Note: Given n will be a posi原创 2017-07-09 14:33:33 · 438 阅读 · 0 评论 -
LeetCode-594. Longest Harmonious Subsequence(Java)
We define a harmonious array is an array where the difference between its maximum value and its minimum value is exactly 1.Now, given an integer array, you need to find the length of its longest h原创 2017-07-09 11:11:57 · 390 阅读 · 0 评论 -
LeetCode-121. 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),原创 2017-07-08 15:16:46 · 349 阅读 · 0 评论 -
LeetCode-504. Base 7 (Java)
Given an integer, return its base 7 string representation.Example 1:Input: 100Output: "202"Example 2:Input: -7Output: "-10"----------------------------------------------------------原创 2017-06-28 11:22:03 · 594 阅读 · 0 评论 -
LeetCode-258. Add Digits
Given 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 = 2. Since 2 has on原创 2017-06-15 18:21:35 · 286 阅读 · 0 评论 -
LeetCode-371. Sum of Two Integers (Java)
使用位运算实现进位,进行无运算符求和。原创 2017-06-15 15:01:59 · 398 阅读 · 0 评论 -
LeetCode-572. Subtree of Another Tree (Java)
Given two non-empty binary trees s and t, check whether tree t has exactly the same structure and node values with a subtree of s. A subtree of s is a tree consists of a node in s and all of this no原创 2017-07-06 12:52:29 · 454 阅读 · 0 评论 -
LeetCode-217. 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原创 2017-06-27 11:17:38 · 498 阅读 · 0 评论 -
LeetCode-628. Maximum Product of Three Numbers (Java)
Given an integer array, find three numbers whose product is maximum and output the maximum product.Example 1:Input: [1,2,3]Output: 6Example 2:Input: [1,2,3,4]Output: 24原创 2017-06-27 10:02:38 · 1544 阅读 · 0 评论 -
LeetCode-506. Relative Ranks (Java)
通过引入新数组,高效解决问题原创 2017-06-23 14:45:43 · 640 阅读 · 0 评论 -
LeetCode-496. Next Greater Element I (java)
You are given two arrays (without duplicates) nums1 and nums2 where nums1’s elements are subset of nums2. Find all the next greater numbers for nums1's elements in the corresponding places of nums原创 2017-06-06 14:24:45 · 777 阅读 · 0 评论 -
LeetCode-448. Find All Numbers Disappeared in an Array (Java)
Given an array of integers where 1 ≤ a[i] ≤ n (n = size of array), some elements appear twice and others appear once.Find all the elements of [1, n] inclusive that do not appear in this array.原创 2017-06-11 13:14:19 · 521 阅读 · 0 评论 -
LeetCode-455. Assign Cookies (Java)
Assume you are an awesome parent and want to give your children some cookies. But, you should give each child at most one cookie. Each child i has a greed factor gi, which is the minimum size of a c原创 2017-06-20 15:04:43 · 410 阅读 · 0 评论 -
LeetCode-557. Reverse Words in a String III
Given a string, you need to reverse the order of characters in each word within a sentence while still preserving whitespace and initial word order.Example 1:Input: "Let's take LeetCode contes原创 2017-06-04 16:58:29 · 422 阅读 · 0 评论 -
LeetCode-566. Reshape the Matrix
耗时5ms,解决思路: 1. 遍历数组先转换为一维数组或存在队列里以便重组 2. 从队列中取数,存入r,c的二维数组中。public class Solution { public int[][] matrixReshape(int[][] nums, int r, int c) { int[][] res=new int[r][c];原创 2017-06-04 13:00:19 · 604 阅读 · 0 评论 -
LeetCode-292. Nim Game (Java)
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原创 2017-06-07 14:18:24 · 421 阅读 · 0 评论 -
LeetCode-530. Minimum Absolute Difference in BST (Java)
Given a binary search tree with non-negative values, find the minimum absolute difference between values of any two nodes.Example:Input: 1 \ 3 / 2Output:1Explanation:原创 2017-06-18 08:51:44 · 900 阅读 · 0 评论 -
LeetCode-167. Two Sum II - Input array is sorted
Given an array of integers that is already sorted in ascending order, find two numbers such that they add up to a specific target number.The function twoSum should return indices of the two number原创 2017-06-17 15:20:00 · 316 阅读 · 0 评论 -
LeetCode-598. Range Addition II (Java)
Given an m * n matrix M initialized with all 0's and several update operations.Operations are represented by a 2D array, and each operation is represented by an array with two positive integers a原创 2017-06-17 15:06:29 · 561 阅读 · 0 评论 -
LeetCode-476 Number Complement
LeetCode 476 Number Complement,利用位运算巧妙解决原创 2017-06-04 10:46:46 · 363 阅读 · 0 评论