![](https://img-blog.csdnimg.cn/20201014180756922.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
Leetcode
胡啦啦
这个作者很懒,什么都没留下…
展开
-
Island Perimeter
You are given a map in form of a two-dimensional integer grid where 1 represents land and 0 represents water. Grid cells are connected horizontally/vertically (not diagonally). The grid is completely s原创 2017-03-09 11:38:28 · 183 阅读 · 0 评论 -
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] Ou原创 2017-03-10 01:16:15 · 285 阅读 · 0 评论 -
Pascal's Triangle II
Total Accepted: 105799 Total Submissions: 297504 Difficulty: Easy Contributors: Admin Given an index k, return the kth row of the Pascal’s triangle.For example, given k = 3, Return [1,3,3,1].Note:原创 2017-03-10 00:50:58 · 277 阅读 · 0 评论 -
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.Here原创 2017-03-07 00:38:14 · 178 阅读 · 0 评论 -
Longest Substring Without Repeating Characters
Given a string, find the length of the longest substring without repeating characters.Examples:Given “abcabcbb”, the answer is “abc”, which the length is 3.Given “bbbbb”, the answer is “b”, with the le原创 2017-03-06 21:47:21 · 191 阅读 · 0 评论 -
Pascal's Triangle
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] ]自己没有想到很好的解法,看了solution,被其代码惊呆了,原创 2017-03-09 21:41:25 · 253 阅读 · 0 评论 -
Longest Consecutive Sequence
Given an unsorted array of integers, find the length of the longest consecutive elements sequence.For example, Given [100, 4, 200, 1, 3, 2], The longest consecutive elements sequence is [1, 2, 3, 4].原创 2017-03-09 21:16:44 · 238 阅读 · 0 评论 -
Surrounded Regions
Given a 2D board containing ‘X’ and ‘O’ (the letter O), capture all regions surrounded by ‘X’.A region is captured by flipping all ‘O’s into ‘X’s in that surrounded region.For example, X X X X X O O原创 2017-03-09 15:22:03 · 232 阅读 · 0 评论 -
Number of Islands
Given a 2d grid map of ‘1’s (land) and ‘0’s (water), count the number of islands. An island is surrounded by water and is formed by connecting adjacent lands horizontally or vertically. You may assume原创 2017-03-09 14:27:48 · 226 阅读 · 0 评论 -
Add Two Numbers
leetcode的第二道题目,自己先通过自己的笨办法写了一下,大致思路就是把两个listnode转换为真正的数,经过相加,取逆,再转换为Listnode输出。算法勉强通过,每次运行时间有一定的差异, 大致在150ms左右,先把自己的代码贴出来,再学习一下其他好的解法。 class Solution(object): def addTwoNumbers(self, l1, l2):原创 2017-03-06 16:42:24 · 171 阅读 · 0 评论 -
Two Sum
Two Sum这道题是进入leetcode的第一道题目,大致的思路最开始就是暴力解法,将数组中的每两个数相加,然后和target相比,计算了下复杂度,大概在O(n2)。换个思路,用target减去当前的数,在从数组中查询是否存在这个数。但是没有想到hash的办法,导致其实复杂度还是在O(n2)。但也通过了测试,看了网上有很多种办法,可以逐一学习一下。主要的方法有两种: 1. 先排序然后用双指针向中原创 2016-01-18 17:35:25 · 388 阅读 · 0 评论 -
Single Number
Given an array of integers, every element appears twice except for one. Find that single one.Note: Your algorithm should have a linear runtime complexity. Could you implement it without using extra me原创 2017-03-07 20:06:36 · 225 阅读 · 0 评论