LeetCode
remanented
勤思考,哈工大在读硕士。
展开
-
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: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: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: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: 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 评论 -
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 评论 -
递归实现迷宫求解&初步动态编程
一.递归迷宫求解: 需要求解上图中的迷宫问题,可以使用使用递归的方式;需要考虑到的几个问题是,当乌龟依次的北南西东方向去尝试找到出口,若是遇到了墙,只能原路返回到前一个点时,要注意陷入无限递归;这个递归问题可以由四个base case组成:1.乌龟遇到了墙,所以无法继...原创 2019-06-13 18:45:30 · 386 阅读 · 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 评论 -
搜索和排序算法学习汇总:search & sort algorithm
Searching 这部分包括了无序列表下的search和有序列表下的searchhttps://blog.csdn.net/oqqSSH/article/details/784427601.无序列表下的search 在无序的列表下只能够遍历搜索了,因为数据之间没有任何结构,代码如下:1 def sequentialSearch(alist, item):...原创 2019-06-21 22:18:46 · 809 阅读 · 0 评论