基本算法
文章平均质量分 91
CSU_ICELEE
艰苦奋斗的程序员
展开
-
单源最短路径 :Dijkstra算法
单源最短路径,看算法还是挺简单的,但是要用算法实现起来并不容易。本人表示看了好久,算法上面的某些变量不明确,看了很久也没看懂,只能在网上查找了。1、单源最短路径概念:给定一个带权有向图G=(V,E),其中每条边的权是一个实数。另外,还给定V中的一个顶点,称为源。现在要计算从源到其他所有各顶点的最短路径长度。这里的长度就是指路上各边权之和。这个问题通常称为单源最短路径问题。原创 2016-10-22 22:30:37 · 1003 阅读 · 0 评论 -
每日一道算法题——Longest Valid Parentheses
最长合法圆括号题目Given a string containing just the characters ‘(’ and ‘)’, find the length of the longest valid (well-formed) parentheses substring.For “(()”, the longest valid parentheses substring is “()”,原创 2017-02-14 11:17:58 · 546 阅读 · 0 评论 -
每日一道编程题——求比当前数值大的新排列
求比当前数值大的新排列Implement next permutation, which rearranges numbers into the lexicographically next greater permutation of numbers.If such arrangement is not possible, it must rearrange it as the lowest原创 2017-02-12 14:02:26 · 723 阅读 · 0 评论 -
每日一道算法题——3个数字相加等于0
3位数字相加等于0题目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 con原创 2017-02-11 14:59:26 · 8114 阅读 · 0 评论 -
每日一道算法题——Container with Most Water
Container with Most Water问题描述 Given n non-negative integers a1, a2, …, an, where each represents a point at coordinate (i, ai). n vertical lines are drawn such that the two endpoints of line i is at原创 2017-02-10 14:27:07 · 794 阅读 · 0 评论 -
每日一道算法题——最长回文字串
最长回文字串题目 Given a string s, find the longest palindromic substring in s. You may assume that the maximum length of s is 1000. Example: Input: “babad” Output: “bab” Note: “aba” is also a val原创 2017-02-09 13:46:45 · 427 阅读 · 0 评论 -
每日一道算法题——Remove Nth Node From End of List
去掉倒数第n的节点题目Given a linked list, remove the nth node from the end of list and return its head.For example, Given linked list: 1->2->3->4->5, and n = 2. After removing the second node from the end翻译 2017-02-17 16:46:05 · 498 阅读 · 0 评论 -
每日一道算法题——2
求两个有序数组的中位数题目 There are two sorted arrays nums1 and nums2 of size m and n respectively. Find the median of the two sorted arrays. The overall run time complexity should be O(log (m+n)). Exampl原创 2017-02-08 13:51:12 · 392 阅读 · 0 评论 -
查找第K大元素
查找第k大元素问题描述给定一个无需数组a,长度为n,以及一个整数k(0问题分析首先大家能够想到的,就是把数组进行排序,然后找出下标为k的元素。如果是用快速排序,那么整个过程的时间复杂度是O(nlogn),显然不够好。接着上面的分析,如果用快速排序,但是明显我们这个题目不需要把整个数组都排序,只需要排一部分就可以了(在代码中能够体会到)。好,我们就在快排的基础上改进一下。不了解快速排序的话,可原创 2017-02-08 12:25:07 · 1847 阅读 · 0 评论 -
每日一道算法题——Letter Combinations of a Phone Number
电话号码的字母组合题目Given a digit string, return all possible letter combinations that the number could represent.A mapping of digit to letters (just like on the telephone buttons) is given below.Input:Digit st原创 2017-02-16 14:42:02 · 523 阅读 · 0 评论 -
每日一道算法题——1
求字符串字串的长度。原创 2017-02-07 13:06:28 · 2092 阅读 · 0 评论 -
三种基础排序(冒泡、选择、插入排序)
这是本人的第一篇博客,看了刘未鹏大神的《暗时间》,想想还是应该写点博客,虽然内容都是从比人那里学来的,但是用自己的话去再诠释一遍,可能会有意外的收获。好了,废话就到这里了,下面开始用最简单的方式介绍这三种排序吧。1、冒泡排序冒泡排序的过程,就是将数组里面的元素不断向后冒,一趟下来,最大的冒到了最后。这样说也许很不生动形象,来举一个例子就明白了。a[ ] = {1,4,2,64,2,原创 2016-10-22 15:36:41 · 638 阅读 · 0 评论 -
每日一篇算法题——数独
数独问题题目Write a program to solve a Sudoku puzzle by filling the empty cells. Empty cells are indicated by the character ‘.’. You may assume that there will be only one unique solution. A sudoku puzz翻译 2017-02-15 15:46:41 · 1050 阅读 · 0 评论