leetcode
ncst
这个作者很懒,什么都没留下…
展开
-
LeetCode 415. Add Strings
LeetCode 415. Add Strings题目要求: Given two non-negative numbers num1 and num2 represented as string, return the sum of num1 and num2.Note:The length of both num1 and num2 is < 5100. Both num1 and num2原创 2016-10-21 13:53:36 · 366 阅读 · 0 评论 -
LeetCode405 Convert a Number to Hexadecimal
题目要求Given an integer, write an algorithm to convert it to hexadecimal. For negative integer, two’s complement method is used.Note:All letters in hexadecimal (a-f) must be in lowercase. The hexadecimal原创 2016-10-22 18:30:39 · 411 阅读 · 0 评论 -
LeetCode405 Convert a Number to Hexadecimal
LeetCode405 Convert a Number to Hexadecimal想到了一种新的方法,比以前的方法的效率要稍微好一些public class solution { public String toHex(int num) { StringBuffer sb = new StringBuffer(); //使用逻辑右移的方式进行处理 char[]原创 2016-10-22 21:16:41 · 287 阅读 · 0 评论 -
LeetCode121 Best Time to Buy and Sell Stock
题目要求: 121. Best Time to Buy and Sell Stock QuestionEditorial Solution My SubmissionsTotal Accepted: 139457Total Submissions: 364702Difficulty: EasyContributors: AdminSay you have an array f原创 2016-10-24 16:26:56 · 330 阅读 · 0 评论 -
LeetCode 70. 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?Subscribe to see which compani原创 2016-10-24 17:17:06 · 311 阅读 · 0 评论 -
LeetCode342. Power of Four 简单解法
题目要求:Given an integer (signed 32 bits), write a function to check whether it is a power of 4.Example:Given num = 16, return true. Given num = 5, return false.Follow up: Could you solve原创 2016-10-25 13:50:56 · 312 阅读 · 0 评论 -
LeetCode 198 robber house
题目要求: 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 tha原创 2016-10-25 16:09:20 · 247 阅读 · 0 评论 -
LeetCode 345.Reverse Vowels of a String
题目要求:Write a function that takes a string as input and reverse only the vowels of a string.Example 1: Given s = “hello”, return “holle”.Example 2: Given s = “leetcode”, return “leotcede”.这个题目本身并没有给原创 2016-10-25 17:02:08 · 197 阅读 · 0 评论 -
LeetCode 28Implement strStr() 寻找子字符串的下标的位置
题目要求: Returns the index of the first occurrence of needle in haystack, or -1 if needle is not part of haystack.题目不难,可以直接使用暴力搜索的方式进行处理public class solution { public int strStr(String haystack, Stri原创 2016-11-05 19:20:14 · 372 阅读 · 0 评论 -
LeetCode165 Compare Version Number 比较版本号
题目要求: 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 an原创 2016-11-05 20:07:03 · 938 阅读 · 0 评论 -
LeetCode 7. Reverse Integer 倒序输出数字
题目要求:Reverse digits of an integer.Example1: x = 123, return 321 Example2: x = -123, return -321click to show spoilers.Have you thought about this? Here are some good questions to ask before coding. B原创 2016-11-05 20:42:35 · 335 阅读 · 0 评论 -
LeetCode168 Excel Sheet Column Title
题目要求:Given a positive integer, return its corresponding column title as appear in an Excel sheet.For example:1 -> A2 -> B3 -> C...26 -> Z27 -> AA28 -> AB简单点说:这一题目相当于是 10进制转换 26进制注意点:在临界的条件到来时对代码原创 2016-11-05 21:44:16 · 231 阅读 · 0 评论 -
LeetCode 278. 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 on the原创 2016-11-05 22:44:27 · 154 阅读 · 0 评论 -
LeetCode 27.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-10-25 17:59:53 · 201 阅读 · 0 评论 -
LeetCode 118Pascal's triangle.
题目要求: Given numRows, generate the first numRows of ` For example, given numRows = 5, Return [ [1], [1,1], [1,2,1], [1,3,3,1], [1,4,6,4,1]原创 2016-10-26 16:54:48 · 196 阅读 · 0 评论 -
LeetCode 26 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 with原创 2016-10-26 17:35:16 · 263 阅读 · 0 评论 -
LeetCode172 Factorial Trailing Zeroes
题目要求: Given an integer n, return the number of trailing zeroes in n!.Note: Your solution should be in logarithmic time complexity.解题思路: 末尾0的个数 其实是与 5 的个数相当 注意: 25=5*5…public class soluti原创 2016-10-26 18:13:46 · 188 阅读 · 0 评论 -
LeetCode 119. Pascal's Triangle II
题目要求:Given an index k, return the kth row of the Pascal’s triangle. For example, given k = 3, Return [1,3,3,1].public class solution { public List<Integer> getRow(int rowIndex) { //使用数组循环的原创 2016-10-27 20:00:00 · 205 阅读 · 0 评论 -
LeetCode 9.Palindrome Number 回文数算法
这一个题目是判断回文数 题目要求:Determine whether an integer is a palindrome. Do this without extra space.click to show spoilers.Some hints: Could negative integers be palindromes? (ie, -1)If you are thinking of co原创 2016-10-28 10:42:06 · 279 阅读 · 0 评论 -
LeetCode223 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.Rectangle Area Assume tha原创 2016-10-28 13:57:35 · 266 阅读 · 0 评论 -
LeetCode205 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 anothe原创 2016-10-28 17:46:37 · 371 阅读 · 0 评论 -
LeetCode344 一行代码解决
LeetCode344 一行代码解决题目要求: Write a function that takes a string as input and returns the string reversed. Example: Given s = “hello”, return “olleh”.package com.syy.leetcode344;public class LeetCode_ne原创 2016-10-16 15:34:39 · 529 阅读 · 1 评论 -
LeetCode171 Excel Sheet Column Number
题目要求: Excel Sheet Column NumberRelated 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原创 2016-10-19 15:40:02 · 210 阅读 · 0 评论 -
LeetCode290 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.Exam原创 2016-10-29 16:54:42 · 251 阅读 · 0 评论 -
LeetCode20 Valid Parentheses
题目要求: 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 vali原创 2016-10-29 19:45:41 · 236 阅读 · 0 评论 -
LeetCode217 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 elemen原创 2016-10-20 14:50:40 · 266 阅读 · 0 评论 -
LeetCode22 Merge Sorted Array
题目要求: Given two sorted integer arrays nums1 and nums2, merge nums2 into nums1 as one sorted array.Note: You may assume that nums1 has enough space (size that is greater or equal to m + n) to hold add原创 2016-10-31 11:54:21 · 184 阅读 · 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.Subscribe to see which companies asked this questionpackage com.syy.leetcode13;public class原创 2016-10-21 10:02:44 · 267 阅读 · 0 评论 -
LeeCode 58. 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.Note: A word is def原创 2016-10-31 15:39:53 · 278 阅读 · 0 评论 -
LeetCode14 Longest Common Prefix 确定最长的前缀字符串
题目要求: * Write a function to find the longest common prefix string amongst an array of strings. * 计算最长公共前缀解题思路: 使用循环的方式进行处理运算public class Solution { public String longestCommonPrefix(String原创 2016-10-31 16:52:43 · 328 阅读 · 0 评论 -
LeetCode396 Rotate Function
题目要求: Given an array of integers A and let n to be its length.Assume Bk to be an array obtained by rotating the array A k positions clock-wise, we define a “rotation function” F on A as follow:F(k) =原创 2016-11-01 22:17:24 · 199 阅读 · 0 评论 -
LeetCode414 Third Maximum Number
题目要求:Given a non-empty array of integers, return the third maximum number in this array. If it does not exist, return the maximum number. The time complexity must be in O(n).Example 1: Input: [3, 2, 1原创 2016-11-01 22:57:51 · 235 阅读 · 0 评论 -
LeetCode448 Find All Numbers Disappeared in an Array(java/python)
题目要求: 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.Co原创 2016-11-30 15:07:17 · 1531 阅读 · 0 评论 -
LeetCode 38.Submission Details
题目要求: 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 “one原创 2016-11-14 22:49:44 · 201 阅读 · 0 评论 -
LeetCode38 Count and Say(C语言解决)
题目要求: 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 “one原创 2016-11-15 12:13:21 · 2079 阅读 · 0 评论 -
LeetCode 104Maximum 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-11-15 12:42:58 · 256 阅读 · 0 评论 -
LeerCode167 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 numb原创 2016-12-05 18:01:36 · 248 阅读 · 0 评论 -
LeetCode238 Product of Array Except Self(java and python solution)
题目要求: Given an array of n integers where n > 1, nums, return an array output such that output[i] is equal to the product of all the elements of nums except nums[i].Solve it without division and in O(n原创 2016-12-06 11:49:33 · 317 阅读 · 0 评论 -
LeetCode384. Shuffle an Array
题目要求: Shuffle a set of numbers without duplicates.Example:// Init an array with set 1, 2, and 3. int[] nums = {1,2,3}; Solution solution = new Solution(nums);// Shuffle the array [1,2,3] and return原创 2016-12-06 14:33:56 · 499 阅读 · 0 评论 -
LeetCode maximum subarray
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原创 2016-12-08 17:07:03 · 226 阅读 · 0 评论