算法
拼了命的珍惜
力气大的搬砖男子汉。
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
算法设计:快速排序
template<class Type> void quickSort(Type a[],int l,int r){ if(l<r){ int p = partition(a,l,r); quickSort(a,l,p-1); quickSort(a,p+1,r); } template<class Type> int partition(Type a[],int l,int r){ int i=l,j=r+1; Type x=a[l]; while(原创 2020-07-27 22:05:07 · 528 阅读 · 0 评论 -
算法设计:合并排序
public void mergeSortDemo(int[] array){ mergeSort(array,0,array.length-1); } public void mergeSort(int[] array,int l,int r){ if(l>=r)return ;//当序列左边界大于等于右边界,结束 int mid = (l+r)>>1;//取中点 mergeSort(array,l,mid);//对左边序列递归分割 mergeSort(array,mid+1原创 2020-07-27 21:52:21 · 326 阅读 · 0 评论 -
算法设计:整数因子分解问题
对n的每个因子递归搜索。 void solve(int n){ if(n == 1)total++; else{ for(int i=2; i<=n; i++)if(n%i == 0)solve(n/i); } }原创 2020-07-27 21:14:58 · 629 阅读 · 0 评论 -
【java-海明距离】477. Total Hamming Distance
The Hamming distance between two integers is the number of positions at which the corresponding bits are different. Now your job is to find the total Hamming distance between all pairs of the given numbers. Example: Input: 4, 14, 2 Output: 6 Explanation: I原创 2020-07-05 15:58:41 · 284 阅读 · 0 评论 -
【java-动态规划】62. Unique Paths
A robot is located at the top-left corner of a m x n grid (marked ‘Start’ in the diagram below). The robot can only move either down or right at any point in time. The robot is trying to reach the bottom-right corner of the grid (marked ‘Finish’ in the dia原创 2020-07-05 15:06:53 · 311 阅读 · 0 评论 -
【split分割】468. Validate IP Address
Write a function to check whether an input string is a valid IPv4 address or IPv6 address or neither. IPv4 addresses are canonically represented in dot-decimal notation, which consists of four decimal numbers, each ranging from 0 to 255, separated by dots原创 2020-07-03 22:15:19 · 321 阅读 · 0 评论 -
【java-快速幂】50. Pow(x, n)
Implement pow(x, n), which calculates x raised to the power n (xn). Example 1: Input: 2.00000, 10 Output: 1024.00000 Example 2: Input: 2.10000, 3 Output: 9.26100 Example 3: Input: 2.00000, -2 Output: 0.25000 Explanation: 2-2 = 1/22 = 1/4 = 0.25 Note: -100.原创 2020-07-03 12:26:16 · 284 阅读 · 0 评论 -
[快速排序]148. Sort List
Sort a linked list in O(n log n) time using constant space complexity. Example 1: Input: 4->2->1->3 Output: 1->2->3->4 Example 2: Input: -1->5->3->4->0 Output: -1->0->3->4->5 /** * Definition for singly-linked lis原创 2020-07-02 22:31:25 · 248 阅读 · 0 评论 -
【暴力法】8. String to Integer (atoi)
Implement atoi which converts a string to an integer. The function first discards as many whitespace characters as necessary until the first non-whitespace character is found. Then, starting from this character, takes an optional initial plus or minus sign原创 2020-07-01 23:17:08 · 281 阅读 · 0 评论 -
【大数库暴力法】7. Reverse Integer
Given a 32-bit signed integer, reverse digits of an integer. Example 1: Input: 123 Output: 321 Example 2: Input: -123 Output: -321 Example 3: Input: 120 Output: 21 Note: Assume we are dealing with an environment which could only store integers within the 3原创 2020-07-01 18:30:43 · 234 阅读 · 0 评论 -
【java大数库暴力】给出两个 非空 的链表用来表示两个非负的整数。其中,它们各自的位数是按照 逆序 的方式存储的,并且它们的每个节点只能存储 一位 数字。
给出两个 非空 的链表用来表示两个非负的整数。其中,它们各自的位数是按照 逆序 的方式存储的,并且它们的每个节点只能存储 一位 数字。 如果,我们将这两个数相加起来,则会返回一个新的链表来表示它们的和。 您可以假设除了数字 0 之外,这两个数都不会以 0 开头。 示例: 输入:(2 -> 4 -> 3) + (5 -> 6 -> 4) 输出:7 -> 0 -> 8 原因:342 + 465 = 807 class ListNode { int val;转载 2020-06-30 22:35:39 · 1378 阅读 · 0 评论
分享