![](https://img-blog.csdnimg.cn/20201014180756928.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
算法
hf寒沨
Coding...
展开
-
如何不使用第三个变量来交换两个数的值
如何不使用第三个变量来交换两个数的值原创 2017-08-11 19:52:40 · 464 阅读 · 0 评论 -
【LeetCode】338. Counting Bits
Problem:Given a non negative integer number num. For every numbers i in the range 0 ≤ i ≤ num calculate the number of 1's in their binary representation and return them as an array.Example:For num = 5...原创 2018-04-25 10:30:53 · 138 阅读 · 0 评论 -
【LeetCode】238. Product of Array Except Self
Problem:Given 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 it without division and i...原创 2018-04-25 11:28:48 · 125 阅读 · 0 评论 -
【LeetCode】328. Odd Even Linked List
Problem:Given a singly linked list, group all odd nodes together followed by the even nodes. Please note here we are talking about the node number and not the value in the nodes.You should try to do i...原创 2018-05-04 16:27:50 · 307 阅读 · 0 评论 -
【LeetCode】19. Remove Nth Node From End of List
Given a linked list, remove the n-th node from the end of list and return its head.Example:Given linked list: 1->2->3->4->5, and n = 2.After removing the second node from the end, the li...原创 2018-05-04 16:35:14 · 119 阅读 · 0 评论 -
【LeetCode】92. Reverse Linked List II
Problem:Reverse a linked list from position m to n. Do it in one-pass.Note: 1 ≤ m ≤ n ≤ length of list.Example:Input: 1->2->3->4->5->NULL, m = 2, n = 4Output: 1->4->3->2->5...原创 2018-05-04 16:51:46 · 125 阅读 · 0 评论 -
【LeetCode】234. Palindrome Linked List
Problem:Given a singly linked list, determine if it is a palindrome.Follow up:Could you do it in O(n) time and O(1) space?题目:给定一个单链表,判断是否为回文?最好时间复杂度O(n),空间复杂度为 O(1)。 思路:除去要求,最简单的方法则是用stack...原创 2018-05-05 21:00:24 · 200 阅读 · 0 评论 -
Java中数组赋值
1,数组操作中,可以使用等于(=)赋值,注意:此时新数组只是指向原数组的存储空间,并没有重新申请新的空间。2,第二种使用System.ararycopy方法System.arraycopy(originalArray, 0, targetArray, 0, originalArray.length);此时,新数组重新申请存储地址空间,再将原数组中数据拷贝过来。...原创 2018-07-10 14:53:06 · 14311 阅读 · 0 评论 -
【LeetCode】199. Binary Tree Right Side View
Problem:Given a binary tree, imagine yourself standing on the right side of it, return the values of the nodes you can see ordered from top to bottom.题目:给定一个二叉树,输出从右侧看到的节点(大致就是每层的最右侧的节点).思路:做的二叉...原创 2018-10-29 15:55:00 · 135 阅读 · 0 评论 -
【LeetCode】209. Minimum Size Subarray Sum
Problem:Given an array of n positive integers and a positive integer s, find the minimal length of a contiguous subarray of which the sum ≥ s. If there isn't one, return 0 instead.题目:给定一个长度为n正整数数组和一...原创 2018-12-09 22:31:41 · 138 阅读 · 0 评论 -
【数据结构】Trie Tree:字典树(前缀树)的实现
字典树又称为前缀树或Trie树,是处理字符串常见的数据结构。假设组成所有单词的字符仅为a-z。字典树介绍字典树是一种树形结构,优点是利用字符串的公共前缀来节约存储空间,比如加入"abc"、“abcd”、“abd”、“b”、“bcd”、“efg”、"hik"之后,字典树如图所示。基本特性根节点没有字符路径。除了根节点外,每一个节点都被一个字符路径找到。从根节点到某一节点,将路径上经过的...原创 2019-01-19 15:54:31 · 753 阅读 · 0 评论 -
【算法】回溯算法
百度百科回溯算法实际上一个类似枚举的搜索尝试过程,主要是在搜索尝试过程中寻找问题的解,当发现已不满足求解条件时,就“回溯”返回,尝试别的路径。回溯法是一种 选优搜索法,按选优条件向前搜索,以达到目标。但当探索到某一步时,发现原先选择并不优或达不到目标,就退回一步重新选择,这种走不通就退回再走的技术为回溯法,而满足回溯条件的某个状态的点称为“回溯点”。许多复杂的,规模较大的问题都可以使用回溯法...原创 2019-01-10 11:11:58 · 194 阅读 · 0 评论 -
大数据和空间限制(未完)
大数据和空间限制认识布隆过滤器题目1:不安全网页的黑名单包含100亿个黑名单网页,每个网页的URL最多占用63B。现在想要实现一种网页过滤系统,可以根据网页的URL判断该网页是否在黑名单上,请设计该系统。只用2GB内存在20亿个整数中找到出现次数最多的数题目2:有一个包含20亿个全是32位整数的大文件,在其中找到出现次数最多的数。40亿个非负整数中找到没出现的数认识布隆过滤器题目1:不安全网页...原创 2019-03-20 16:54:43 · 255 阅读 · 0 评论 -
剑指Offer-Java实现
2.2 编程语言面试题2: 实现Singleton模式/** * @ClassName: Singleton * @Description: 静态内部内 * @author hf寒沨 * @date 2019年4月7日 下午4:55:39 * */public class Singleton { private Singleton() { } public static...原创 2019-04-07 22:00:33 · 608 阅读 · 0 评论 -
【Java】HashMap源码分析
HashMap源码分析继承和接口静态变量关键方法1. hashCode()2. equals()3. hash()继承和接口继承AbstractMap.java实现接口Map,Cloneable,Serializable静态变量初试容量默认是16 -必须是2的次方 /** * The default initial capacity - MUST be a ...原创 2019-04-27 00:33:00 · 428 阅读 · 0 评论 -
【算法】GeoHash
两篇介绍的不错的文章,先记录下https://www.cnblogs.com/mafeng/p/7908620.htmlhttps://www.cnblogs.com/LBSer/p/3392491.html原创 2019-09-21 23:26:29 · 146 阅读 · 0 评论 -
【LeetCode】725. Split Linked List in Parts
Problem:Given a (singly) linked list with head node root, write a function to split the linked list into k consecutive linked list "parts".The length of each part should be as equal as possible: no tw...原创 2018-05-09 15:14:07 · 307 阅读 · 3 评论 -
【LeetCode】80. Remove Duplicates from Sorted Array II
Problem:Given a sorted array nums, remove the duplicates in-place such that duplicates appeared at most twice and return the new length.Do not allocate extra space for another array, you must do this ...原创 2018-05-02 10:45:47 · 144 阅读 · 0 评论 -
【LeetCode】82. Remove Duplicates from Sorted List II
Given a sorted linked list, delete all nodes that have duplicate numbers, leaving only distinct numbers from the original list.Example 1:Input: 1->2->3->3->4->4->5Output: 1->2-&g...原创 2018-05-02 00:43:39 · 96 阅读 · 0 评论 -
斐波那契数列实用解法
斐波那契数列实用解法,时间复杂度为O(n)原创 2017-09-11 17:02:22 · 248 阅读 · 0 评论 -
LeetCode: 7. Reverse Integer
本题限制为32位数,即逆转有溢出可能,此外,还要考虑,输入的数为负数和0此类情况。int reverse(int x) { unsigned int n=0; int flag=0,i=0; int temp; if(x<0){ flag=1; x=-x; } if(x==0){ return 0; } while((x%10)==0){ x=x/10; }; while(x!=0...原创 2018-04-02 09:47:36 · 92 阅读 · 0 评论 -
LeetCode: 9. Palindrome Number
题目:Determine whether an integer is a palindrome. Do this without extra space.大致意思:判断整数是否回文,不需要额外空间。对于“Do this without extra space” 我以为是不需要再申请变量空间,懵逼》》》查看solution中发现还是有申请变量,OK!class Solution { publi...原创 2018-04-02 09:48:45 · 180 阅读 · 0 评论 -
LeetCode: 14. Longest Common Prefix
题目:Write a function to find the longest common prefix string amongst an array of strings.找出字符串数组最长的公共前缀Solution中的算法:class Solution { public String longestCommonPrefix(String[] strs) { if (st...原创 2018-04-02 09:52:34 · 126 阅读 · 0 评论 -
LeetCode: 20. Valid Parentheses
Given a string containing just the characters '(', ')', '{', '}', '[' and ']', determine if the input string is valid.The brackets must close in the correct order, "()" and "()[]{}" are all valid but ...原创 2018-04-02 09:53:22 · 103 阅读 · 0 评论 -
LeetCode: 136. Single Number
Given an array of integers, every element appears twice except for one. Find that single one.Note:Your algorithm should have a linear runtime complexity. Could you implement it without using extra mem...原创 2018-04-02 09:54:10 · 105 阅读 · 0 评论 -
LeetCode:344. Reverse String
Write a function that takes a string as input and returns the string reversed.Example:Given s = "hello", return "olleh".题意:将一个String字符串逆转。思路:直接遍历逆转输出。嗯,恭喜,超时!!!懵逼,看大神,使用内置函数StringBuilder。在此之前,我以为内置函数的...原创 2018-04-02 09:54:56 · 139 阅读 · 0 评论 -
【LeetCode】 69. Sqrt(x)
题目:求平方根。。。必须返回的是整数,就是小数点要舍弃。思路:直接用轮子。。。sqrt()代码:class Solution { public int mySqrt(int x) { return (int)Math.sqrt(x); }}...原创 2018-04-03 22:44:46 · 139 阅读 · 0 评论 -
【LeetCode】461. Hamming Distance
Problem:The Hamming distance between two integers is the number of positions at which the corresponding bits are different.Given two integers x and y, calculate the Hamming distance.题目:求汉明距离,即两个数不同位数的...原创 2018-04-23 09:26:34 · 163 阅读 · 0 评论 -
【LeetCode】448. Find All Numbers Disappeared in an Array
Problem:Given an array of integers where 1 ≤ a[i] ≤ n (n = size of array), some elements appear twice and others appear once.Find all the elements of [1, n] inclusive that do not appear in this array....原创 2018-04-23 10:31:26 · 113 阅读 · 0 评论 -
【LeetCode】771. Jewels and Stones
Problem:You're given strings J representing the types of stones that are jewels, and S representing the stones you have. Each character in Sis a type of stone you have. You want to know how many of ...原创 2018-04-23 11:47:00 · 206 阅读 · 0 评论 -
【LeetCode】561. Array Partition I
Problem:Given an array of 2n integers, your task is to group these integers into n pairs of integer, say (a1, b1), (a2, b2), ..., (an, bn) which makes sum of min(ai, bi) for all i from 1 to n as large...原创 2018-04-23 14:30:20 · 125 阅读 · 0 评论 -
【LeetCode】821. Shortest Distance to a Character
Problem:Given a string S and a character C, return an array of integers representing the shortest distance from the character C in the string.题目:给定一个字符串S和字符C,返回一个整型数组,数组每一位表示字符串对应下标位字符距离C字符的最短距离。思路:首先...原创 2018-04-23 15:52:34 · 487 阅读 · 2 评论 -
【LeetCode】371. Sum of Two Integers
Problem:Calculate the sum of two integers a and b, but you are not allowed to use the operator + and -.Example:Given a = 1 and b = 2, return 3.题目:计算a和b的和,不使用加减运算符。思路:使用异或,与等逻辑运算。(参考计算机组成原理中补码加减法等)使用异或...原创 2018-04-23 16:56:41 · 98 阅读 · 0 评论 -
【LeetCode】3. Longest Substring Without Repeating Characters
Problem: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 "b", wi...原创 2018-05-01 17:15:54 · 117 阅读 · 0 评论 -
【JVM虚拟机】垃圾收集算法
垃圾收集算法1. 标记-清除算法2. 复制算法3. 标记-整理算法4. 分代收集算法1. 标记-清除算法最基础的收集算法:“标记-清除”(Mark-Sweep)算法,算法分为两个阶段:“标记”和“清除”。算法过程标记:首先标记处所有需要回收的对象(通过引用计数法和可达性分析判定是否可回收);清除:完成标记后,统一回收所有被标记的对象。缺点效率问题,标记和清除两个过程的效率都不高;...原创 2019-09-25 18:24:07 · 139 阅读 · 0 评论