
LeetCode
Bright's Dream
计算机专业本科生,web技术爱好者
展开
-
Leetcode题解1:最长回文子串 JAVA
Leetcode题解1:最长回文子串 JAVA题目Given a string s, find the longest palindromic substring in s. You may assume that the maximum length of s is 1000.Example 1:Input: "babad"Output: "bab"Note: "aba" is al...原创 2019-02-22 20:46:44 · 119 阅读 · 0 评论 -
LeetCode题解:Permutations JavaScript
Given a collection of distinct integers, return all possible permutations.Example:Input: [1,2,3]Output:[[1,2,3],[1,3,2],[2,1,3],[2,3,1],[3,1,2],[3,2,1]]代码/** * @param {number[]} nums * ...原创 2019-03-30 08:42:02 · 138 阅读 · 0 评论 -
LeetCode题解12:对称树
Symmetric TreeGiven 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 / \ / \...原创 2019-03-04 20:27:13 · 259 阅读 · 0 评论 -
LeetCode题解11:爬楼梯
Climbing StairsYou 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...原创 2019-03-04 18:32:34 · 248 阅读 · 0 评论 -
LeetCode题解10:子数组的最大值
Maximum SubarrayGiven an integer array nums, find the contiguous subarray (containing at least one number) which has the largest sum and return its sum.Example:Input: [-2,1,-3,4,-1,2,1,-5,4],Outpu...原创 2019-03-04 18:07:59 · 596 阅读 · 0 评论 -
LeetCode题解14:Generate Parentheses
LeetCode题解14:Generate ParenthesesGiven n pairs of parentheses, write a function to generate all combinations of well-formed parentheses.For example, given n = 3, a solution set is:[ "((()))", "...原创 2019-03-09 20:54:38 · 119 阅读 · 0 评论 -
LeetCode题解13:Letter Combinations of a Phone Number
Given a string containing digits from 2-9 inclusive, return all possible letter combinations that the number could represent.A mapping of digit to letters (just like on the telephone buttons) is give...原创 2019-03-09 10:44:39 · 144 阅读 · 0 评论 -
LeetCode题解9:寻找插入位置
Search Insert PositionGiven 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 dupl...原创 2019-03-04 09:20:32 · 155 阅读 · 0 评论 -
LeetCode题解8:寻找子串
Implement strStr().Return the index of the first occurrence of needle in haystack, or -1 if needle is not part of haystack.Example 1:Input: haystack = "hello", needle = "ll"Output: 2Example 2:I...原创 2019-03-03 15:30:56 · 542 阅读 · 0 评论 -
LeetCode题解7:移除元素
题目Given an array nums and a value val, 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 by modifying the input ar...原创 2019-03-03 07:41:35 · 105 阅读 · 0 评论 -
Leetcode题解3:字符串转整数
题目Implement atoi which converts a string to an integer.The function first discards as many whitespace characters as necessary until the first non-whitespace character is found. Then, starting from t...原创 2019-02-22 20:49:43 · 132 阅读 · 0 评论 -
Leetcode题解2:整数反转
题目Given a 32-bit signed integer, reverse digits of an integer.Example 1:Input: 123Output: 321Example 2:Input: -123Output: -321Example 3:Input: 120Output: 21Note:Assume we are dealing wi...原创 2019-02-22 20:48:02 · 175 阅读 · 0 评论 -
Leetcode题解 Search in Rotated Sorted Array
Suppose an array sorted in ascending order is rotated at some pivot unknown to you beforehand.(i.e., [0,1,2,4,5,6,7] might become [4,5,6,7,0,1,2]).You are given a target value to search. If found in...原创 2019-03-29 08:49:41 · 131 阅读 · 0 评论