
LeetCode题解
文章平均质量分 56
对面『胶己人』
This is my note, not my blog
展开
-
695. Max Area of Island
题目很简单,现在给出我的解答代码:class Solution {public: int maxAreaOfIsland(vectorvectorint>>& grid) { int result = 0; vectorvectorint> > flag(grid.size()); for (int i = 0; i < grid.si原创 2018-01-21 10:24:00 · 167 阅读 · 0 评论 -
★★★25. Reverse Nodes in k-Group
题目描述Given a linked list, reverse the nodes of a linked list k at a time and return its modified list.k is a positive integer and is less than or equal to the length of the linked list. If the numb...原创 2018-04-18 11:38:01 · 168 阅读 · 0 评论 -
23. Merge k Sorted Lists
题目描述Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity.Example:Input: [ 1->4->5, 1->3->4, 2->6 ] Output: 1->1->2-&...原创 2018-04-17 21:44:04 · 195 阅读 · 0 评论 -
19. Remove Nth Node From End of List
题目描述Given a linked list, remove the n-th node from the end of list and return its head.Example:Given linked list: 1->2->3->4->5, and n = 2.After removing the second node from the e...原创 2018-04-17 19:45:29 · 151 阅读 · 0 评论 -
2. Add Two Numbers
题目描述You are given two non-empty linked lists representing two non-negative integers. The digits are stored in reverse order and each of their nodes contain a single digit. Add the two numbers and re...原创 2018-04-17 10:36:54 · 165 阅读 · 0 评论 -
566. Reshape the Matrix
题目描述:In MATLAB, there is a very useful function called ‘reshape’, which can reshape a matrix into a new one with different size but keep its original data.You’re given a matrix represented by a tw原创 2018-01-20 21:27:17 · 168 阅读 · 0 评论 -
561. Array Partition I
题目描述:Given an array of 2n integers, your task is to group these integers into n pairs of integer, say (a1, b1), (a2, b2), …, (an, bn) which makes sum of min(ai, bi) for all i from 1 to n as large as原创 2018-01-20 17:42:23 · 203 阅读 · 0 评论 -
414. 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,原创 2018-01-25 11:03:05 · 167 阅读 · 0 评论 -
581. Shortest Unsorted Continuous Subarray
题目描述:Given an integer array, you need to find one continuous subarray that if you only sort this subarray in ascending order, then the whole array will be sorted in ascending order, too.You need t原创 2018-01-24 10:57:52 · 181 阅读 · 0 评论 -
167. 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 nu原创 2018-01-21 20:16:59 · 208 阅读 · 0 评论 -
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 by modif原创 2018-01-23 20:41:33 · 166 阅读 · 0 评论 -
724. Find Pivot Index
题目描述Given an array of integers nums, write a method that returns the “pivot” index of this array.We define the pivot index as the index where the sum of the numbers to the left of the index is equ原创 2018-01-22 22:22:34 · 214 阅读 · 0 评论 -
628. Maximum Product of Three Numbers
题目描述:Given an integer array, find three numbers whose product is maximum and output the maximum product.Example 1: Input: [1,2,3] Output: 6Example 2: Input: [1,2,3,4] Output: 2原创 2018-01-22 15:43:51 · 207 阅读 · 0 评论 -
697. Degree of an Array
题目描述:Given a non-empty array of non-negative integers nums, the degree of this array is defined as the maximum frequency of any one of its elements.Your task is to find the smallest possible lengt原创 2018-01-22 11:00:11 · 197 阅读 · 0 评论 -
448. Find All Numbers Disappeared in an Array
题目描述: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原创 2018-01-21 11:17:51 · 188 阅读 · 0 评论 -
82. Remove Duplicates from Sorted List II
题目描述Given a sorted linked list, delete all nodes that have duplicate numbers, leaving only distinct numbers from the original list.For example, Given 1->2->3->3->4->4->5, return...原创 2018-04-18 14:10:42 · 157 阅读 · 0 评论