
LeetCode 刷题
屿-Z
这个作者很懒,什么都没留下…
展开
-
LeetCode11 Container With Most Water Java解法
题意分析给定 n 个非负整数 a1,a2,…,an,每个数代表坐标中的一个点 (i, ai) 。画 n 条垂直线,使得垂直线 i 的两个端点分别为 (i, ai) 和 (i, 0)。找出其中的两条线,使得它们与 x 轴共同构成的矩形可以容纳最多的水。注意:你不能倾斜容器,n 至少是2 比较容易想到的解法,0(n2) 遍历全部 class Solution { pub...原创 2019-01-10 22:08:37 · 301 阅读 · 0 评论 -
Leetcode算法Java全解答--18. 四数之和
题目给定一个包含 n 个整数的数组 nums 和一个目标值 target,判断 nums 中是否存在四个元素 a,b,c 和 d ,使得 a + b + c + d 的值与 target 相等?找出所有满足条件且不重复的四元组。注意:答案中不可以包含重复的四元组。示例:给定数组 nums = [1, 0, -1, 0, -2, 2],和 target = 0。满足要求的四元组集合为:...原创 2019-02-25 10:27:46 · 315 阅读 · 0 评论 -
算法设计——解决 3Sum 以及 3Sum Closest 问题
常写算法,多动脑,不会老!3Sum问题: 若不考虑效率问题,则解决该问题的思路就很简单直接,三个 for 循环遍历穷举即可。一个优秀的程序员肯定不能忍受这么无脑的时间复杂度,于是先想到先对全部数据进行排序操作,然后设置三个指针,数组的首尾各一,第三个指针从首位+1开始。设置合理的条件限制,移动指针。该过程中需要解决去重问题。废话不多说,贴代码: vector<vecto...转载 2019-02-25 00:01:07 · 203 阅读 · 0 评论 -
Leetcode 989:数组形式的整数加法
对于非负整数 X 而言,X 的数组形式是每位数字按从左到右的顺序形成的数组。例如,如果 X = 1231,那么其数组形式为 [1,2,3,1]。给定非负整数 X 的数组形式 A,返回整数 X+K 的数组形式。示例 1:输入:A = [1,2,0,0], K = 34输出:[1,2,3,4]解释:1200 + 34 = 1234123解释 2:输入:A = [2,7,4], K = ...原创 2019-02-28 11:02:29 · 426 阅读 · 0 评论 -
LeetCode string刷题49 Group Anagrams
原题:Given an array of strings, group anagrams together.For example, given: ["eat", "tea", "tan", "ate", "nat", "bat"], Return:[ ["ate", "eat","tea"], ["原创 2019-01-16 12:01:50 · 111 阅读 · 0 评论 -
LeetCode206
. Reverse Linked List Reverse a singly linked list.Example:Input: 1->2->3->4->5->NULLOutput: 5->4->3->2->1->NULLclass Solution { public ListNode reverse...原创 2019-01-08 21:43:55 · 140 阅读 · 0 评论 -
LeetCode string系列刷题 Java 58. Length of Last Word
Given a string s consists of upper/lower-case alphabets and empty space characters ' ', return the length of last word in the string.If the last word does not exist, return 0.Note: A word is defi...原创 2019-01-13 11:16:12 · 161 阅读 · 0 评论 -
LeetCode 4 JAVA Median of Two Sorted Arrays
题目如下:There are two sorted arrays nums1 and nums2 of size m and n respectively.Find the median of the two sorted arrays. The overall run time complexity should be O(log (m+n)).You may assume nums...原创 2019-01-11 21:31:45 · 467 阅读 · 2 评论 -
leetcode twosum Java解法
题目:Given an array of integers, return indices of the two numbers such that they add up to a specific target.You may assume that each input would have exactly one solution, and you may not use the ...转载 2019-01-06 18:36:46 · 128 阅读 · 0 评论 -
48. Rotate Image
The idea was firstly transpose the matrix and then flip it symmetrically. For instance,1 2 3 4 5 67 8 9after transpose, it will be swap(matrix[i][j], matrix[j]...原创 2019-03-12 23:47:03 · 139 阅读 · 0 评论