Introduction to Algorithms
一袖云
这个作者很懒,什么都没留下…
展开
-
快速排序
源代码:import java.util.Scanner;/** * * @author liuzhenzhao */public class MyQuickSort { /** * @param args the command line arguments */ public static void QuickSort(int []A,in...原创 2018-08-14 17:20:24 · 93 阅读 · 0 评论 -
最大堆排序
package heapsort;import java.util.ArrayList;import java.util.List;import java.util.Stack;/** * * @author liuzhenzhao */class MyHeapSort{ private int heap_size; public MyHeapSort(int...原创 2018-08-12 16:00:35 · 83 阅读 · 0 评论 -
leetcode原题--将字符串切割为若干回文子串的最小切割次数
leetcode题目:Given a string s, partition s such that every substring of the partition is a palindrome.Return the minimum cuts needed for a palindrome partitioning of s.For example, given s =”aab”, ...原创 2018-08-15 10:23:17 · 717 阅读 · 0 评论 -
Kruskal算法求最小生成树(图是连通的)
Kruskal算法求图的最小生成树:Kruskal算法本质上上是贪心算法,即每次从图中选取权重最小的安全边(安全边就是加入最小生成树中不会形成回路的边)加入最小生成树(刚开始为空集)中,然后把改边从原图中剔除,继续重复前面的步骤,直到从原图中剔除所有的边或者原图中所有顶点均加入到生成树中。下面就是由一个图的邻接矩阵求其最小生成树的代码:/* * To change this licens...原创 2018-08-22 21:48:25 · 1137 阅读 · 1 评论 -
Parlindrome-Partitioning
class Solution {public: vector<vector<string>> partition(string s) { vector<vector<string>> res; vector<string> cur;原创 2018-08-21 21:32:39 · 212 阅读 · 0 评论 -
求【1...N】的全排列
对于部分有序数组,想要寻找最大值,最简单的方法是遍历,时间复杂度为O(n),但我们可以由有序性想到利用二叉查找,比如:对于一个先升后降数组,寻找其中最大值 for example: input:1 2 3 4 5 6 6 1 output:6 input: 1 2 3 4 5 6 7 8 9 6 4 3 2 1 output: 9 这是一道面试题,现在整理如下:#include&l...原创 2018-09-05 23:42:57 · 384 阅读 · 0 评论 -
单链表排序
单链表排序初始化:#include <stdio.h>#include <stdlib.h>#include <stdbool.h>//节点结构struct node{ int val; struct node * next;};typedef struct node node, * list;//打印函数void pr...转载 2018-10-10 09:42:01 · 604 阅读 · 0 评论 -
剑指offer:找出数组中只出现一次的两个数字
一个整型数组里除了两个数字之外,其他的数字都出现了偶数次。请写程序找出这两个只出现一次的数字。#include<unordered_map>class Solution {public://num1和num2分别保存这两个只出现一次的数字 void FindNumsAppearOnce(vector<int> data,int* num1,int *num2...原创 2018-10-10 10:48:19 · 181 阅读 · 0 评论 -
leetcode: 删除链表中的冗余结点
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-...原创 2018-10-10 11:28:10 · 331 阅读 · 0 评论