Leetcode
打算开始刷Leetcode,建立这个专栏来纪录一下刷题中遇到自己与大佬们之间的差距以及学习到的点。
remanented
勤思考,哈工大在读硕士。
展开
-
Leetcode:subset && Recursive Knowledge
给定一组不含重复元素的整数数组nums,返回该数组所有可能的子集(幂集)。说明:解集不能包含重复的子集。示例:输入: nums = [1,2,3]输出:[ [3],[1],[2],[1,2,3],[1,3],[2,3],[1,2],[]]解法一,使用库itertool中的combination()库函数来求解,combinati...原创 2019-06-12 09:36:28 · 243 阅读 · 0 评论 -
LeetCode:maxSubArray
给定一个整数数组nums,找到一个具有最大和的连续子数组(子数组最少包含一个元素),返回其最大和。输入: [-2,1,-3,4,-1,2,1,-5,4],输出: 6解释:连续子数组[4,-1,2,1] 的和最大,为6。第一个想到的思路就是暴力求解,但是自己写的暴力求解也没有测试成功,因为花费的时间复杂度为0(n*n),参考了一下别人的暴力求解方案,时间复杂度为0(n):...原创 2019-06-11 14:53:13 · 400 阅读 · 0 评论 -
LeetCode:Search Insert Position
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.E...原创 2019-06-10 17:29:05 · 116 阅读 · 0 评论 -
LeetCode:Implement strStr()
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: 2题目的要求是寻找...原创 2019-06-09 21:05:53 · 142 阅读 · 0 评论 -
Leetcode: Remove Element
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 arra...原创 2019-06-09 00:15:35 · 122 阅读 · 0 评论 -
LeetCode:Valid Parentheses && Remove Duplicates from Sorted Array
Given a string containing just the characters '(', ')', '{', '}', '[' and ']', determine if the input string is valid.An input string is valid if: Open brackets must be closed by the same type ...原创 2019-06-07 10:20:15 · 97 阅读 · 0 评论 -
LeetCode:Longest Common prefix
Write a function to find the longest common prefix string amongst an array of strings. If there is no common prefix, return an empty string"".Example 1:Input: ["flower","flow","flight"]Output: ...原创 2019-06-06 10:19:27 · 237 阅读 · 0 评论 -
LeetCode:Roman to Integer
Roman numerals are represented by seven different symbols:I,V,X,L,C,DandM. Symbol Value I 1 V 5 X 10 L 50 C 100 D 500 M 1000。For example,two is written asIIin Roman numeral, just two one...原创 2019-06-05 09:50:18 · 166 阅读 · 0 评论 -
LeetCode:Reverse Integer & PalindromeNumber
Given a 32-bit signed integer, reverse digits of an integer.Example 1: Input: 123 Output: 321;Example 2:Input: -123 Output: -321;Example 3:Input: 120 Output: 21Note:Assume we are dealing with ...原创 2019-06-04 15:22:30 · 132 阅读 · 0 评论 -
Leetcode: TwoSum
题目:Given an array of integers, returnindicesof the two numbers such that they add up to a specific target.You may assume that each input would haveexactlyone solution, and you may not use thesame...原创 2019-06-03 11:32:30 · 135 阅读 · 0 评论