Algorithm
cl723401
这个作者很懒,什么都没留下…
展开
-
1.堆排序java实现
public class HeapSort { /** * 调整aaray[parent,end]范围为最大堆 * @param array * @param parent * @param end */ public static void heapAdjust(int[] array,int parent,int end){ int left = parent*...原创 2019-03-04 09:48:33 · 162 阅读 · 0 评论 -
13.LeetCode 804. Unique Morse Code Words
题目:class Solution { public int uniqueMorseRepresentations(String[] words) { String[] codes = {".-","-...","-.-.","-..",".","..-.","--.","....","..",".---","-.-",".-..","--","-....原创 2019-03-26 08:32:34 · 129 阅读 · 0 评论 -
14.Java实现二分搜索树
package com.cl.set;import java.util.LinkedList;import java.util.Queue;/** * 二分搜索树 * @param <E> */public class BST<E extends Comparable<E>>{ private class Node{ ...原创 2019-03-26 08:34:19 · 123 阅读 · 0 评论 -
15.Java实现自己的带虚拟头节点的单链表
package com.cl.set;public class LinkedList<E> { private class Node{ public E e; public Node next; public Node(E e, Node next) { this.e = e; ...原创 2019-03-26 08:35:52 · 269 阅读 · 1 评论 -
16.基于二分搜索树实现Map
package com.cl.map;import com.cl.set.FileOperation;import java.util.ArrayList;public class BSTMap<K extends Comparable<K>,V> implements Map<K,V> { private class Node{ ...原创 2019-03-26 08:39:37 · 125 阅读 · 0 评论 -
17.Java基于二分搜索树实现Set
package com.cl.set;public class BSTSet<E extends Comparable<E>> implements Set<E> { private BST<E> bst; public BSTSet() { bst=new BST<>(); } ...原创 2019-03-26 08:41:56 · 242 阅读 · 0 评论 -
18.Java基于LinkedList实现Map
package com.cl.map;import com.cl.set.FileOperation;import com.cl.set.LinkedList;import java.util.ArrayList;public class LinkedListMap<K,V> implements Map<K,V> { private class ...原创 2019-03-26 08:43:20 · 246 阅读 · 0 评论 -
19.基于LinkedList实现set
package com.cl.set;public class LinkedListSet<E> implements Set<E> { private LinkedList<E> list; public LinkedListSet() { list = new LinkedList<>(); }...原创 2019-03-26 08:45:37 · 422 阅读 · 0 评论 -
20.二分查找
1.分清指针的边界值意义,采用两种不同的边界值指针进行二分搜索二分查找适合有序数组的查找,每次与数组的中间元素对比,小的话,左半部分查找,大的话右半部分查找public class BinarySearch<T extends Comparable> { /** * 二分查找 * @param arr * @param n ...原创 2019-04-26 08:49:50 · 147 阅读 · 0 评论 -
11.Leetcode:350--Intersection of Two Arrays II
题目:使用Map:public class IntersectionDupSolution { public int[] intersect(int[] nums1, int[] nums2) { //元素,次数 TreeMap<Integer,Integer> map = new TreeMap<>(); ...原创 2019-03-26 08:28:17 · 93 阅读 · 0 评论 -
12.LeetCode:Intersection of Two Arrays
题目:使用集合:public class IntersectionOfArraySolution { public int[] intersection(int[] nums1, int[] nums2) { TreeSet<Integer> set = new TreeSet<>(); for (int num:n...原创 2019-03-26 08:26:18 · 109 阅读 · 0 评论 -
10.LeetCode 80:Remove Duplicates from Sorted Array II
1.题目2.解决package com.cl.ch2;import java.util.Arrays;public class RemoveDuplicatesTwice { /** * 时间复杂度O(n) * 空间复杂度O(1) * @param nums * @return */ public int r...原创 2019-03-19 18:55:20 · 101 阅读 · 0 评论 -
2.快速排序Java实现
public class QuickSortSolution{ //对array[l,r]排序 public static void quickSort(int [] array,int l,int r){ //只剩一个元素或者l>r时完成了排序 if(l>=r){ return ; } //找锚定点 ,pivot所对应的结点已经在正确的位置上 int ...原创 2019-03-04 10:07:54 · 118 阅读 · 0 评论 -
3.归并排序Java实现及优化
public class MergeSort { /** * 归并排序,归并array[l,r] * @param array * @param l * @param r */ public static void mergeSort(int array[] ,int l,int r){ if(l>=r){ return ; } int mid ...原创 2019-03-04 10:37:07 · 182 阅读 · 0 评论 -
4.找字符串数组中所有字符串中都出现相同次数的字符
题目:public class FindCommonStrings { public static List<String> commonChars(String[] A) { if(A.length<0||A.length>100){ return null; } if(A[0].equals("")) ret...原创 2019-03-04 10:50:31 · 842 阅读 · 0 评论 -
5.链表逆序存放两个数求和
/** * 两个链表存放着数字:1->2->3+1->4->5=2->6->8 321+541=862 * 1->2->3+1->4=2->6->3 321+41=362 * @author CL * */public class LinkListAddNums { public static List...原创 2019-03-04 11:05:28 · 234 阅读 · 0 评论 -
6.Leetcode 424:Longest Repeating Character Replacement
题目:Longest Repeating Character Replacement:Given a string that consists of only uppercase English letters, you can replace any letter in the string with another letter at mostktimes. Find the le...原创 2019-03-15 09:48:36 · 141 阅读 · 0 评论 -
7.LeetCode:283,Move Zeroes
1.题目:2.解法package com.cl.ch2;import java.util.Arrays;public class MoveZeros { //时间复杂度:O(n) //空间复杂度:O(n) public void moveZeroes(int[] nums) { int[] temp = new int[nums....原创 2019-03-19 18:34:55 · 131 阅读 · 0 评论 -
8.LeetCode:Remove Element
1.题目:2.解答:package com.cl.ch2;import java.util.Arrays;public class RemoveElement { /** * 时间复杂度:O(n) * 空间复杂度:O(1) * @param nums * @param val * @return */ ...原创 2019-03-19 18:37:54 · 102 阅读 · 0 评论 -
9.LeetCode 26:Remove Duplicates from Sorted Array
1.题目2.解决package com.cl.ch2;import java.util.Arrays;public class RemoveDuplicates { /** * 时间复杂度:O(n) * 空间复杂度:O(1) * @param nums * @return */ public int remov...原创 2019-03-19 18:42:37 · 133 阅读 · 0 评论 -
21.LeetCode 283: MoveZeros
题目:/** * 283 */public class MoveZeros { //时间复杂度:O(n) //空间复杂度:O(n) public void moveZeroes(int[] nums) { int[] temp = new int[nums.length]; int j=0; for(int...原创 2019-04-26 09:10:18 · 160 阅读 · 0 评论