
leetcode
文章平均质量分 70
chenyx90
这个作者很懒,什么都没留下…
展开
-
9. Palindrome Number
Determine whether an integer is a palindrome. Do this without extra space.public class Solution { public boolean isPalindrome(int x) { String s=Integer.toString(x); char[] a=s原创 2016-01-27 21:52:29 · 440 阅读 · 0 评论 -
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 · 426 阅读 · 0 评论 -
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.因为有前边的一些练习,这道题目做起来简直是太简单。主要思路:用一原创 2016-01-08 15:30:45 · 365 阅读 · 0 评论 -
7. Reverse Integer 翻转一个整数
Reverse digits of an integer.Example1: x = 123, return 321Example2: x = -123, return -321对于这道题目,如果超出整数限制,那么返回0public class Solution { public int reverse(int x) { int a=Math原创 2016-01-25 15:12:41 · 367 阅读 · 0 评论 -
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 · 347 阅读 · 0 评论 -
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 legibility)P A H NA P L S I转载 2016-01-25 12:44:33 · 445 阅读 · 0 评论 -
Binary Tree Level Order Traversal II 从底部倒着输出二叉树每一层的元素
Given a binary tree, return the bottom-up level order traversal of its nodes' values. (ie, from left to right, level by level from leaf to root).For example:Given binary tree {3,9,20,#,#,15,7},原创 2016-01-07 13:54:15 · 423 阅读 · 0 评论 -
5. Longest Palindromic Substring 找出给定字符串中最长的子字符串
Given a string S, find the longest palindromic substring in S. You may assume that the maximum length of S is 1000, and there exists one unique longest palindromic substring.转载出处:http://www.cn转载 2016-01-24 19:45:04 · 441 阅读 · 0 评论 -
4. 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)).public class Solution {原创 2016-01-24 15:46:06 · 255 阅读 · 0 评论 -
3. Longest Substring Without Repeating Characters 无重复字符的最长子字符串
Given a string, find the length of the longest substring without repeating characters. For example, the longest substring without repeating letters for "abcabcbb" is "abc", which the length is 3. For转载 2016-01-16 21:25:54 · 318 阅读 · 0 评论 -
2. Add Two Numbers 给定的两个链表是逆序排列的,相加后放在一个新的链表里边
You are given two linked lists representing two non-negative numbers. The digits are stored in reverse order and each of their nodes contain a single digit. Add the two numbers and return it as a link原创 2016-01-16 18:13:06 · 387 阅读 · 0 评论 -
1. Two Sum 给定一个数组和一个数,输出两个和为给定数的数组元素的下标
Given an array of integers, find two numbers such that they add up to a specific target number.The function twoSum should return indices of the two numbers such that they add up to the target, where原创 2016-01-16 16:03:43 · 435 阅读 · 0 评论 -
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 · 245 阅读 · 0 评论 -
Lowest Common Ancestor of a Binary Search Tree
转载出处 http://blog.youkuaiyun.com/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 · 431 阅读 · 0 评论 -
Binary Tree Level Order Traversal 二叉树的层序遍历
Given a binary tree, return the level order traversal of its nodes' values. (ie, from left to right, level by level).For example:Given binary tree {3,9,20,#,#,15,7}, 3 / \ 9 20 /原创 2016-01-08 19:45:34 · 304 阅读 · 0 评论 -
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 · 248 阅读 · 0 评论 -
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 · 254 阅读 · 0 评论 -
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 · 297 阅读 · 0 评论 -
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 · 380 阅读 · 0 评论 -
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 · 445 阅读 · 0 评论 -
8. String to Integer (atoi)
Implement atoi to convert a string to an integer.Hint: Carefully consider all possible input cases. If you want a challenge, please do not see below and ask yourself what are the possible input ca原创 2016-01-27 17:28:14 · 305 阅读 · 0 评论 -
Summary Ranges 有序数组找出连续的子数组并且输出
出处:http://blog.youkuaiyun.com/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 · 337 阅读 · 0 评论 -
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 · 460 阅读 · 0 评论 -
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 · 243 阅读 · 0 评论 -
Merge Sorted Array合并两个有序数组
Given two sorted integer arrays nums1 and nums2, merge nums2 intonums1 as one sorted array.Note:You may assume that nums1 has enough space (size that is greater or equal tom + n) to hold addit转载 2016-01-09 12:00:36 · 364 阅读 · 0 评论 -
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./** * Defin转载 2016-01-08 22:39:32 · 364 阅读 · 0 评论 -
Symmetric Tree 是不是对称树
Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center).For example, this binary tree is symmetric: 1 / \ 2 2 / \ / \3 4 4 3But the following转载 2016-01-08 21:49:46 · 272 阅读 · 0 评论 -
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 · 979 阅读 · 0 评论 -
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 · 287 阅读 · 0 评论 -
Balanced Binary Tree 判断二叉树是否是高度相差不超过1的高度平衡的二叉树
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 ofevery node never differ转载 2016-01-06 14:39:33 · 359 阅读 · 0 评论 -
Compare Version Numbers 比较版本号,输入是以小数点为分隔符的字符串数字
Compare two version numbers version1 and version2.If version1 > version2 return 1, if version1 version2 return -1, otherwise return 0.You may assume that the version strings are non-empty and co转载 2016-01-01 17:44:32 · 1222 阅读 · 0 评论 -
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 · 336 阅读 · 0 评论 -
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 · 355 阅读 · 0 评论 -
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 · 262 阅读 · 0 评论 -
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 · 257 阅读 · 0 评论 -
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 · 381 阅读 · 0 评论 -
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 · 266 阅读 · 0 评论 -
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 · 652 阅读 · 0 评论 -
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 · 301 阅读 · 0 评论 -
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 · 708 阅读 · 0 评论