三元组相加获得结果最接近target 3SumClosest 给定一个数组,选择三个元素相加,结果必须为所有三元组中最接近target的值,返回这个三元组的和。 Given an array S of n integer…
分类:LeetCode
[LeetCode] Counting Bits 计数位
Given a non negative integer number num. For every numbers i in the range 0 ≤ i ≤ num calculate the num…
[LeetCode] Linked List Random Node 链表随机节点
Given a singly linked list, return a random node’s value from the linked list. Each node must hav…
[LeetCode] Subarray Sum Equals K 子数组和为K
Given an array of integers and an integer k, you need to find the total number of continuous subar…
[LeetCode] Asteroid Collision 行星碰撞
We are given an array asteroids of integers representing asteroids in a row. For each asteroi…
LeetCode | Binary Tree Level Order Traversal
题目: Given a binary tree, return the level order traversal of its nodes’ values. (ie, from left…
前言
我叫skys215,是一名bug工程师。 我接触编程的时间比较早,但是因为我数学不好加上比较懒,所以编程能力一直没有多少提升。 虽然在大学期间被同学们视为大神、学霸,其实我心里知道比我厉害的人多了去了。 参加了几次校内A…
二刷380. Insert Delete GetRandom O(1)
Medium 题目要求是Design a data structure that supports all following operations in average O(1) time.难点在于remove的时候如…
LeetCode 746. Min Cost Climbing Stairs
DP解法:定义一个dp数组,dp[i]为到达第i层的最小花费,dp[i]仅与dp[i-1]和dp[i-2]和相应层的cost值有关,满足:dp[i] = min(dp[i-2] + cost[i-2] , dp[i-1]…
[LeetCode] Max Sum of Rectangle No Larger Than K 最大矩阵和不超过K
Given a non-empty 2D matrix matrix and an integer k, find the max sum of a rectangle in …
[LeetCode] Sentence Similarity II 句子相似度之二
Given two sentences words1, words2 (each represented as an array of strings), and a list of s…
[剑指offer] 反转链表
题目描述 输入一个链表,反转链表后,输出新链表的表头。 解题思路 设置三个指针,head为当前节点,pre为当前节点的前一个节点,next为当前节点的下一个节点,需要pre和next的目的是让当前节点从pre->h…