![](https://img-blog.csdnimg.cn/20201014180756927.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
Algorithm
DoUUnderstand
这个作者很懒,什么都没留下…
展开
-
剑指Offer 1.二维数组中的查找
题目描述 在一个二维数组中,每一行都按照从左到右递增的顺序排序,每一列都按照从上到下递增的顺序排序。请完成一个函数,输入这样的一个二维数组和一个整数,判断数组中是否含有该整数。思路:首先我们选择从左下角开始搜寻,(为什么不从左上角开始搜寻,左上角向右和向下都是递增,那么对于一个点,对于向右和向下会产生一个岔路;如果我们选择从左下脚开始搜寻的话,如果大于就向右,如果小于就向上)。public cla原创 2017-05-03 17:50:00 · 355 阅读 · 0 评论 -
一致性哈希
首先我们可以看看为什么需要一致性哈希算法。假设我们有3台Redis缓存服务器,编号为0,1,2.现在我们想将3万张图片均匀的缓存存到这3台服务器上。因为不想在缓存中找某张图片时去遍历3台服务器,所以我们原始的做法是对缓存项的键进行哈希,将哈希后的结果对服务器的数量进行取模操作。hash(图片名称) % 3 这样当我们访问任意一张图图片时,就能快速的找出该图片被缓存在哪个服务器上 ...原创 2018-02-27 16:29:34 · 411 阅读 · 0 评论 -
LeetCode 大纲
自己刷LeetCode的题目链接汇总以及分类数组问题1.K sum问题 求数组内K个元素之和为某定值的集合Leetcode 1.Two Sum2Sum通过HashMap辅助,找到相加为target的值 Leetcode 15.3Sum3Sum确定一个数,然后找另外两个数相加等于其相反数即可 Leetcode 16.3Sum Closest Leetcode 18. 4原创 2018-01-09 17:17:54 · 379 阅读 · 0 评论 -
LeetCode 80. Remove Duplicates from Sorted Array II
Follow up for “Remove Duplicates”: What if duplicates are allowed at most twice?For example, Given sorted array nums = [1,1,1,2,2,3],Your function should return length = 5, with the first five e原创 2018-01-10 14:11:02 · 176 阅读 · 0 评论 -
LeetCode 27. Remove Element
Given an array and a value, remove all instances of that value in-place and return the new length.Do not allocate extra space for another array, you must do this by modifying the input array in-plac原创 2018-01-09 17:07:07 · 238 阅读 · 0 评论 -
Leetcode 283. Move Zeros
Given an array nums, write a function to move all 0’s to the end of it while maintaining the relative order of the non-zero elements.For example, given nums = [0, 1, 0, 3, 12], after calling your fu原创 2018-01-09 16:16:21 · 402 阅读 · 0 评论 -
LeetCode 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 modifying th原创 2018-01-09 17:48:27 · 205 阅读 · 0 评论 -
Leetcode 18. 4Sum
Given an array S of n integers, are there elements a, b, c, and d in S such that a + b + c + d = target? Find all unique quadruplets in the array which gives the sum of target.Note: The solution set原创 2018-01-08 16:01:29 · 226 阅读 · 0 评论 -
Leetcode 15.3Sum
Given an array S of n integers, are there elements a, b, c in S such that a + b + c = 0? Find all unique triplets in the array which gives the sum of zero.Note: The solution set must not contain dup原创 2018-01-08 14:02:28 · 255 阅读 · 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 exactly原创 2018-01-08 15:23:50 · 235 阅读 · 0 评论 -
Leetcode 1.Two Sum
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.Example: Given nums = [2, 7原创 2016-09-18 23:18:17 · 465 阅读 · 0 评论 -
LeetCode 215. Kth Largest Element in an Array
Find the kth largest element in an unsorted array. Note that it is the kth largest element in the sorted order, not the kth distinct element. For example, Given [3,2,1,5,6,4] and k = 2, return 5.N原创 2018-01-12 13:02:59 · 248 阅读 · 0 评论 -
Java版本 排序算法总结
对排序算法总结,考研时本来很熟悉,过段时间很多细节又忘记了,写篇blog总结一下。O(nlogn)首先当n较大,则应采用时间复杂度为O(nlogn)的排序方法:快速排序、堆排序或归并排序。 快速排序:是目前基于比较的内部排序中被认为是最好的方法,当待排序的关键字是随机分布时,快速排序的平均时间最短;快速排序Quick SortArrays.sort()方法底层就用的快速排序和插入排序,对于元素少的原创 2017-10-08 16:36:48 · 773 阅读 · 0 评论 -
Java判断回文字符串
题目描述 判断一个正整数是不是回文数。 回文数的定义是,将这个数反转之后,得到的数仍然是同一个数。public class HuiWenNum { /** * @SERLIN */ public static void main(String[] args) { int n; System.out.prin原创 2017-07-10 10:49:11 · 2833 阅读 · 0 评论 -
剑指Offer 2.替换空格
题目描述 请实现一个函数,将一个字符串中的空格替换成“%20”。例如,当字符串为We Are Happy.则经过替换之后的字符串为We%20Are%20Happy。String中有该直接方法,运用正则表达式public class Solution { public String replaceSpace(StringBuffer str) { return str.toS原创 2017-07-20 10:10:02 · 251 阅读 · 0 评论 -
剑指Offer 链表相关算法
剑指Offer 16 翻转链表剑指Offer 17 合并两个排序的链表剑指Offer 18 链表中倒数第k个结点剑指Offer 16 翻转链表输入一个链表,反转链表后,输出链表的所有元素。public class solution{ public ListNode ReverseList(ListNode head){ if(head...原创 2018-02-28 22:37:40 · 257 阅读 · 0 评论