![](https://img-blog.csdnimg.cn/20201014180756926.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
leetcode
文章平均质量分 71
--asx
这个作者很懒,什么都没留下…
展开
-
21. Merge Two Sorted Lists 和 148. Sort List
Merge two sorted linked lists and return it as a new list. The new list should be made by splicing together the nodes of the first two lists.Example:Input: 1->2->4, 1->3->4Output: 1->1...原创 2018-03-21 20:15:59 · 123 阅读 · 0 评论 -
LC 141. Linked List Cycle
LC 141. Linked List Cycle判断是否是循环列表。方法是使用双指针,一个快指针一个慢指针,快指针每次走两格,慢指针每次走一格。如果快指针先到达列表终点则return false,如果快慢指针相遇则return true这里面涉及到为什么出现环的话,快慢指针一定会相遇的这个问题。class Solution {public: bool hasCycle(ListNode...原创 2018-03-13 17:05:30 · 114 阅读 · 0 评论 -
Leetcode 155. Min Stack 题解
题目链接这道题给普通的Stack加上一个getMin()的操作,注意这个getMin()并不把min值pop出来。所以思路很简单,就是在正常的stack push的时候记录push之后的min值即可。思路就是用另外一个stack来记录当前min值。class MinStack {public: /** initialize your data structure here. */ ...原创 2018-03-06 16:02:44 · 170 阅读 · 0 评论 -
Leetcode 16. 3Sum Closest 题解
题目链接brute force O(n^3)先排一遍序,遍历两个数,第三个数用二分查找,复杂度O(n^2*lgn)遍历一个数,第二、三个数用双指针查找,转化为2Sum Closest问题,复杂度O(n^2)O(n^2lgn) class Solution {public: int threeSumClosest(vector<int>& nums, int targe...原创 2018-03-06 15:00:38 · 180 阅读 · 0 评论 -
LC 206 Reverse a singly linked list.
Reverse a singly linked list.Input : Head of following linked list 1->2->3->4->NULLOutput : Linked list should be changed to, 4->3->2->1->NULLInput : Head of...原创 2018-03-13 15:56:16 · 154 阅读 · 0 评论 -
Leetcode 11 Container With Most Water 题解
Given n non-negative integers a1, a2, ..., an, where each represents a point at coordinate (i, ai). n vertical lines are drawn such that the two endpoints of line i is at (i, ai) and (i, 0). Find two ...原创 2018-03-06 13:15:55 · 138 阅读 · 0 评论 -
LC 153. Find Minimum in Rotated Sorted Array
LC 153. Find Minimum in Rotated Sorted ArraySuppose 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).Find the mini...原创 2018-03-13 08:58:30 · 122 阅读 · 0 评论 -
LC 53. Maximum Subarray
Find the contiguous subarray within an array (containing at least one number) which has the largest sum.For example, given the array [-2,1,-3,4,-1,2,1,-5,4],the contiguous subarray [4,-1,2,1] has the ...原创 2018-03-12 23:09:48 · 136 阅读 · 0 评论 -
LC 238. Product of Array Except Self
238. Product of Array Except SelfGiven an array of n integers where n > 1, nums, return an array output such that output[i] is equal to the product of all the elements of nums except nums[i].Solve ...原创 2018-03-12 23:00:13 · 127 阅读 · 0 评论 -
LC 98. Validate Binary Search Tree
Given a binary tree, determine if it is a valid binary search tree (BST).Assume a BST is defined as follows:The left subtree of a node contains only nodes with keys less than the node's key.The right ...原创 2018-03-12 14:19:46 · 115 阅读 · 0 评论 -
LC 102 Binary Tree Level Order Traversal
基础中的基础,直接背就好了。用队列。因为需要在最后按层序打印,所以队列中记录层数。AC代码/** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(...原创 2018-03-12 13:16:22 · 176 阅读 · 0 评论 -
leetcode回文数相关的题
LC 9 Determine whether an integer is a palindrome. Do this without extra space.基础知识:int x是一个正数,在不考虑溢出的情况下如何获得最后一位:x % 10如何获得除了最后一位的数 x/10如何把一个数字y加到末尾:x*10+y没看答案之前没有什么特别好的想法,看了之后学会了一个构造某个数值的反向序列的方法:递归地...原创 2018-03-21 23:59:49 · 164 阅读 · 0 评论