算法
文章平均质量分 78
hachyli
这个作者很懒,什么都没留下…
展开
-
全排列算法:不含重复元素,包含重复元素,字母序排列
在某些和组合数学有关的背景下,会需要生成全排列一类的数据集合。而生成全排列,最常用的有以下两种算法。转载 2014-07-22 19:48:04 · 1969 阅读 · 0 评论 -
LRU Cache leetcode
Design and implement a data structure for Least Recently Used (LRU) cache. It should support the following operations: get and set.get(key) - Get the value (will always be positive) of the key if原创 2014-09-02 17:06:20 · 363 阅读 · 0 评论 -
Distinct Subsequences leetcode
Given a string S and a string T, count the number of distinct subsequences of T in S.A subsequence of a string is a new string which is formed from the original string by deleting some (can be non原创 2014-09-01 20:11:14 · 299 阅读 · 0 评论 -
求最长单调递减子序列
解法一: 首先将这个序列进行排序,然后再求出已排序的和未排序的这两个数列最长公共子序列解法二:就是用动态规划法来解决问题原创 2014-09-22 16:52:20 · 563 阅读 · 0 评论 -
Merge k Sorted Lists leetcode
Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity.原创 2014-09-22 21:54:29 · 480 阅读 · 0 评论 -
压栈思想计算运算表达式
栈的规则是先进后出。利用压栈的思想来计算四则运算表达式是这样的:我们给定两个栈,一个用来存放数字、一个用来存放对应的操作符。假定我们有一个给定的四则运算表达式a+b+c/d*(e+f)-d*a,那我们先把这个表达式拆分成一个个的数字或者是运算符、或者就是括号了。然后我们从左至右遍历每一个元素,遍历过程中遵循步骤和原则如下: (1)遇到数字则直接压到数字栈顶。 (2)原创 2014-09-22 19:12:12 · 1044 阅读 · 0 评论 -
Best Time to Buy and Sell Stock III leetcode
Say you have an array for which the ith element is the price of a given stock on day i.Design an algorithm to find the maximum profit. You may complete at most two transactions.Note:You ma原创 2014-09-11 15:24:45 · 406 阅读 · 0 评论 -
Scramble String leetcode
https://oj.leetcode.com/problems/scramble-string/原创 2014-09-10 19:39:54 · 638 阅读 · 0 评论 -
堆排序
利用最大堆实现。最大堆:最大堆性质是除了根结点意外的所有结点 i 都要满足A[parent[i]] >= A[i]需要利用到的一个性质:当用数组表示存储n个元素的堆时,叶结点的下标分别是n/2, n/2+1, n/2 + 2, ......,n - 1. (下标从0开始)需要用到的函数有:void max_heapify(int *a, int i) //通原创 2014-09-22 20:10:59 · 391 阅读 · 0 评论 -
Edit Distance leetcode
Given two words word1 and word2, find the minimum number of steps required to convert word1 to word2. (each operation is counted as 1 step.)You have the following 3 operations permitted on a word:原创 2014-08-27 20:50:45 · 443 阅读 · 0 评论 -
Palindrome Partitioning I and II leetcode
Given a string s, partition s such that every substring of the partition is a palindrome.Return all possible palindrome partitioning of s.For example, given s = "aab",Return [ ["aa","原创 2014-08-26 19:38:15 · 366 阅读 · 0 评论 -
Triangle leetcode
Given a triangle, find the minimum path sum from top to bottom. Each step you may move to adjacent numbers on the row below.For example, given the following triangle[ [2], [3,4], [原创 2014-08-21 20:15:07 · 367 阅读 · 0 评论 -
leetcode Minimum Path Sum
Given a m x n grid filled with non-negative numbers, find a path from top left to bottom right which minimizes the sum of all numbers along its path.Note: You can only move either down or right at原创 2014-08-01 09:22:19 · 437 阅读 · 0 评论 -
Single Number II leetcode
Given an array of integers, every element appears three times except for one. Find that single one.Note:Your algorithm should have a linear runtime complexity. Could you implement it without usi原创 2014-07-25 18:57:15 · 408 阅读 · 0 评论 -
LeetCode Unique Binary Search Trees--动态规划思想
Given n, how many structurally unique BST's (binary search trees) that store values 1...n?For example,Given n = 3, there are a total of 5 unique BST's. 1 3 3 2 1 \原创 2014-07-23 19:10:00 · 508 阅读 · 0 评论 -
利用全排列算法八皇后问题和正方体摆数使三组面顶点之和相等问题
全排列算法解决思路见上一篇博客,这里贴出应用全排列算法解决两个w原创 2014-07-22 22:33:03 · 646 阅读 · 0 评论 -
Word Break leetcode
Given a string s and a dictionary of words dict, determine if s can be segmented into a space-separated sequence of one or more dictionary words.For example, givens = "leetcode",dict = ["leet"原创 2014-09-03 09:00:24 · 385 阅读 · 0 评论