![](https://img-blog.csdnimg.cn/20201014180756780.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
算法
文章平均质量分 72
路遥遥丶
这个作者很懒,什么都没留下…
展开
-
【LeetCode】7. Reverse Integer
Reverse digits of an integer. Example1: x = 123, return 321 Example2: x = -123, return -321 click to show spoilers. Note: The input is assumed to be a 32-bit signed integer. Your function s原创 2017-06-09 11:17:27 · 173 阅读 · 0 评论 -
【LeetCode】24. Swap Nodes in Pairs
Given a linked list, swap every two adjacent nodes and return its head. For example, Given 1->2->3->4, you should return the list as 2->1->4->3. Your algorithm should use only constant space. Y原创 2017-10-07 13:09:16 · 210 阅读 · 0 评论 -
【LeetCode】48. Rotate Image
You are given an n x n 2D matrix representing an image. Rotate the image by 90 degrees (clockwise). Follow up: Could you do this in-place? 思路:比较简单,自己列出几个矩阵,找规律就成了 代码如下: public clas原创 2017-07-08 20:11:28 · 146 阅读 · 0 评论 -
【LintCode】打劫房屋
打劫房屋 描述 笔记 数据 评测 假设你是一个专业的窃贼,准备沿着一条街打劫房屋。每个房子都存放着特定金额的钱。你面临的唯一约束条件是:相邻的房子装着相互联系的防盗系统,且 当相邻的两个房子同一天被打劫时,该系统会自动报警。 给定一个非负整数列表,表示每个房子中存放的钱, 算一算,如果今晚去打劫,你最多可以得到多少钱 在不触动报警装置的情况原创 2017-07-05 18:39:11 · 184 阅读 · 0 评论 -
【LintCode】买卖股票的最佳时机
假设有一个数组,它的第i个元素是一支给定的股票在第i天的价格。如果你最多只允许完成一次交易(例如,一次买卖股票),设计一个算法来找出最大利润。 样例 给出一个数组样例 [3,2,3,1,2], 返回 1 思路:简单贪心问题,注意处理边界问题 代码如下:public class Solution { /** * @par原创 2017-06-11 08:44:00 · 246 阅读 · 0 评论 -
【LintCode】合并排序数组 II
合并两个排序的整数数组A和B变成一个新的数组。 注意事项 你可以假设A具有足够的空间(A数组的大小大于或等于m+n)去添加B中的元素 样例 给出 A = [1, 2, 3, empty, empty], B = [4, 5] 合并之后 A 将变成 [1,2,3,4,5] 思路:也是道归并排序题。不过排序可以不增加辅助数组,直接从A的末端原创 2017-06-10 22:16:43 · 583 阅读 · 0 评论 -
【LeetCode】9. Palindrome Number
Determine whether an integer is a palindrome. Do this without extra space. click to show spoilers. Some hints: Could negative integers be palindromes? (ie, -1) If you are thinking of convertin原创 2017-06-09 14:39:55 · 179 阅读 · 0 评论 -
【LeetCode】16. 3Sum Closest
Given an array S of n integers, find three integers in S such that the sum is closest to a given number, target. Return the sum of the three integers. You may assume that each input would have exact原创 2017-07-01 18:21:12 · 163 阅读 · 0 评论 -
【LeetCode】4. 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)). Example 1: nums1 =原创 2017-06-08 14:45:54 · 223 阅读 · 0 评论 -
【LintCode】最大子数组
最大子数组 描述 笔记 数据 评测 给定一个整数数组,找到一个具有最大和的子数组,返回其最大和。 注意事项 子数组最少包含一个数 样例 给出数组[−2,2,−3,4,−1,2,1,−5,3],符合要求的子数组为[4,−1,2,1],其最大和为6 思路:思路很简单,可以原创 2017-06-10 17:47:59 · 246 阅读 · 0 评论 -
【LintCode】删除排序数组中的重复数字
删除排序数组中的重复数字 描述: 给定一个排序数组,在原数组中删除重复出现的数字,使得每个元素只出现一次,并且返回新的数组的长度。 不要使用额外的数组空间,必须在原地没有额外空间的条件下完成。 样例 给出数组A =[1,1,2],你的函数应该返回长度2,此时A=[1,2]。 思路:因为不让使用额外数组空间,所以只能从原来原创 2017-06-09 21:11:46 · 1742 阅读 · 0 评论 -
【LeetCode】3. 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 "原创 2017-10-06 12:58:49 · 207 阅读 · 0 评论