算法
kevinjqy
这个作者很懒,什么都没留下…
展开
-
LeetCode242 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 assume the原创 2017-02-16 12:58:49 · 244 阅读 · 0 评论 -
LeetCode3. Longest Substring Without Repeating Characters
题目Given a string, find the length of the longest substring without repeating characters.Examples:Given “abcabcbb”, the answer is “abc”, which the length is 3.Given “bbbbb”, the answer is “b”, with the原创 2017-11-28 17:40:24 · 664 阅读 · 0 评论 -
leetcode110 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 differ b原创 2017-05-06 15:35:15 · 298 阅读 · 0 评论 -
leetcode257 Binary Tree 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”] 需要得到所有从根到叶子结点的路径。解题思路既然是得到路原创 2017-05-05 21:01:24 · 267 阅读 · 0 评论 -
leetcode118 Pascal's Triangle
题目Given numRows, generate the first numRows of Pascal’s triangle.For example, given numRows = 5, Return[ [1], [1,1], [1,2,1], [1,3,3,1], [1,4,6,4,1]]生成给定行数的帕斯卡三角形。解题思路利用帕斯卡三角形的性质即可很简单的原创 2017-05-05 15:27:51 · 254 阅读 · 0 评论 -
leetcode538 Convert BST to Greater Tree
题目Given a Binary Search Tree (BST), convert it to a Greater Tree such that every key of the original BST is changed to the original key plus sum of all keys greater than the original key in BST.Example原创 2017-04-05 20:31:24 · 766 阅读 · 0 评论 -
leetcode413 Arithmetic Slices
题目A sequence of number is called arithmetic if it consists of at least three elements and if the difference between any two consecutive elements is the same.For example, these are arithmetic sequence:1原创 2017-04-08 15:15:41 · 540 阅读 · 0 评论 -
LeetCode171 Excel Sheet Column Number
题目Given a column title as appear in an Excel sheet, return its corresponding column number.For example:A -> 1B -> 2C -> 3...Z -> 26AA -> 27AB -> 28方法一可以看作把一个26进制的数转化为十进制,根据公式即可。public int titleT原创 2017-02-15 21:40:05 · 286 阅读 · 0 评论 -
LeetCode387 First Unique Character in a String
题目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 may assu原创 2017-02-15 17:19:35 · 277 阅读 · 0 评论 -
LeetCode349 Intersection of Two Arrays
原题Given two arrays, write a function to compute their intersection. Example: Given nums1 = [1, 2, 2, 1], nums2 = [2, 2], return [2]. Note: Each element in the result must be unique. The result can原创 2017-02-14 21:27:36 · 308 阅读 · 0 评论 -
LeetCode202 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 of原创 2017-02-20 21:50:48 · 223 阅读 · 0 评论 -
LeetCode13 Roman to Integer
题目Given a roman numeral, convert it to an integer.Input is guaranteed to be within the range from 1 to 3999.解题思路罗马数字的规则参考这个。 总结起来就是如果前一位数字大于后一位,就加上其值,小于就减去其值,前提是数字长度大于一。public int romanToInt(String s)原创 2017-02-19 14:55:37 · 291 阅读 · 0 评论 -
LeetCode409 Longest Palindrome
题目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 consid原创 2017-02-16 21:27:26 · 282 阅读 · 0 评论 -
LeetCode169 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 alway原创 2017-02-16 19:51:09 · 260 阅读 · 0 评论 -
leetcode 93. Restore IP Addresses
题目Given a string containing only digits, restore it by returning all possible valid IP address combinations.For example: Given “25525511135”,return [“255.255.11.135”, “255.255.111.35”]. (Order ...原创 2017-12-20 10:47:05 · 465 阅读 · 0 评论