LeetCode
CinKateRen
好好学习,天天向上,always learn from the best!
展开
-
LeetCode-13-Roman to Integer(罗马数字转换为整型数字)
Q:Given a roman numeral, convert it to an integer.Input is guaranteed to be within the range from 1 to 3999.Analysis:可以枚举出罗马字母对应的阿拉伯数字,罗马数字来说,如果左边的字符比右边的字符小,则应该减去左边的字符,计算出整型数字;如果左边的字符大于右边的字符,则需加上右边的字符,原创 2017-07-20 17:04:11 · 375 阅读 · 0 评论 -
LeetCode-67-Add Binary(二进制相加)
Q:Given two binary strings, return their sum (also a binary string).For example, a = “11” b = “1” Return “100”.Analysis:刚开始傻傻的以为Java自带API就可以完成,后来试了确实naive了。然后正常思路做题吧,找出最长的二进制字符串,较短的前面补0,依次按各个位相加即可。C原创 2017-08-03 21:44:00 · 256 阅读 · 0 评论 -
LeetCode-70-Climbing Stairs(爬楼梯)
Q: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 positive in原创 2017-08-04 09:29:12 · 218 阅读 · 0 评论 -
LeetCode-107-Binary Tree Level Order Traversal II(二叉树级序遍历<2>)
Q: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,null,null,15,7原创 2017-08-10 11:20:10 · 301 阅读 · 0 评论 -
LeetCode-108-Convert Sorted Array to Binary Search Tree(转化已排序数组到二叉排序树)
Q:Given an array where elements are sorted in ascending order, convert it to a height balanced BST.Analysis:题目要求将已升序的数组转化为二叉排序树;可以使用递归,二分的方法,进行生成二叉排序树。Code:/** * Definition for a binary tree node. *原创 2017-08-11 10:24:51 · 411 阅读 · 0 评论 -
LeetCode-118-Pascal's Triangle(帕斯卡的三角形)
Q: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]]Analysis:基础的算法问题,中间元素值等于“肩上”两元素之和。C原创 2017-08-19 09:53:30 · 333 阅读 · 0 评论 -
LeetCode-28-Implement strStr()(字符串匹配)
Q:Implement strStr().Returns the index of the first occurrence of needle in haystack, or -1 if needle is not part of haystack.Analysis:第一反应就是用基础的KMP算法来实现,也可用其他字符串匹配算法如BM等算法。Code:public class Solution {原创 2017-07-27 18:46:26 · 323 阅读 · 0 评论 -
LeetCode-110-Balanced Binary Tree(平衡二叉树)
Q: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-08-12 15:56:17 · 286 阅读 · 0 评论 -
LeetCode-35-Search Insert Position(搜素并插入指定位置)
Q:Given a sorted array and a target value, return the index if the target is found. If not, return the index where it would be if it were inserted in order.You may assume no duplicates in the array.Her原创 2017-07-28 18:04:40 · 242 阅读 · 0 评论 -
LeetCode-121-Best Time to Buy and Sell Stock(最佳买卖股票的时间)
Q: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), de原创 2017-08-21 09:21:38 · 252 阅读 · 0 评论 -
LeetCode-112-Path Sum(路径和)
Q: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 and sum =原创 2017-08-17 09:13:06 · 208 阅读 · 0 评论 -
LeetCode-111-Minimum Depth of Binary Tree(二叉树的最短路径)
Q: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.Analysis:此题要求返回二叉树根结点到叶子结点最短的距离。可以采用递归的方法原创 2017-08-16 19:07:32 · 343 阅读 · 0 评论 -
LeetCode-101-Symmetric Tree(判断是否为对称树)
Q: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 3But the原创 2017-08-09 15:16:46 · 289 阅读 · 0 评论 -
LeetCode-14-Longest Common Prefix(最长公共前缀)
Q:Write a function to find the longest common prefix string amongst an array of strings.Analysis:先将字符串数组按每个元素的长度从小到大排序,然后用二重循环直接依次判断各个字符数组元素的字符和最短的字符串中的各个字符是否相等并返回。Code:public class Solution { publ原创 2017-07-21 16:42:14 · 244 阅读 · 0 评论 -
LeetCode-20-Valid Parentheses(有效的括号)
Q:Given a string containing just the characters ‘(‘, ‘)’, ‘{‘, ‘}’, ‘[’ and ‘]’, determine if the input string is valid.The brackets must close in the correct order, “()” and “()[]{}” are all valid but原创 2017-07-22 20:35:14 · 199 阅读 · 0 评论 -
LeetCode-38-Count and Say(计数并显示)
Q:The count-and-say sequence is the sequence of integers with the first five terms as following:1. 12. 113. 214. 12115. 1112211 is read off as “one 1” or 11. 11 is read off as原创 2017-07-31 18:08:41 · 211 阅读 · 0 评论 -
LeetCode-9-Palindrome Number(回文数)
Q: 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原创 2017-07-19 17:26:53 · 210 阅读 · 0 评论 -
LeetCode-21- Merge Two Sorted Lists(合并两个已排序链表)
Q:Merge two sorted linked lists and return it as a new list. The new list should be made by splicing together the nodes of the first two lists.Analysis:题目简单,合并两个已排序的链表。需要注意的是,若有相同的元素,并没说要删除,需要“一次链接两个相同原创 2017-07-23 17:08:27 · 306 阅读 · 0 评论 -
LeetCode-53-Maximum Subarray(最大和子串)
Q:Find the contiguous subarray within an array (containing at least one number) which has the largest sum.For example, given the array [-2,1,-3,4,-1,2,1,-5,4], the contiguous subarray [4,-1,2,1] has t原创 2017-08-01 09:53:29 · 196 阅读 · 0 评论 -
LeetCode-26-Remove Duplicates from Sorted Array(消除已排序数组中的重复元素)
Q: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 with co原创 2017-07-24 17:22:05 · 222 阅读 · 0 评论 -
LeetCode-66-Plus One(加一操作)
Q:Given a non-negative integer represented as a non-empty array of digits, plus one to the integer.You may assume the integer do not contain any leading zero, except the number 0 itself.The digits are原创 2017-08-02 08:55:24 · 554 阅读 · 0 评论 -
LeetCode-27-Remove Element(消除数组中给定的元素)
Q: 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.The o原创 2017-07-25 09:37:11 · 233 阅读 · 0 评论 -
LeetCode-771-Jewels and Stones(宝石和石头)
Q:You're given strings J representing the types of stones that are jewels, and S representing the stones you have. Each character in S is a type of stone you have. You want to know how many of the...原创 2018-08-11 22:05:00 · 248 阅读 · 0 评论