
算法
文章平均质量分 68
chruan
这个作者很懒,什么都没留下…
展开
-
如何得到有重复元素的不重复全排列
M个元素中含有相同的元素,如何得到他们的全排列(不重复排列)? 元素表述: a1,a1,...a1, a2,a2,...a2,.......,an,an,...an 其中,a1的个数为N1, a2的个数为N2,以此类推,总个数为M。 则可以证明不重复的排列种类的数目: M!/(N1!*N2!*...*Nn!) 就是将N个数字做全排列。不过对于转载 2012-03-23 16:42:50 · 4634 阅读 · 0 评论 -
leetcode: ZigZag Conversion
题目:ZigZag ConversionThe string "PAYPALISHIRING" is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a fixed font for better legibility)原创 2014-03-03 10:10:14 · 754 阅读 · 0 评论 -
leetcode: Search Insert Position
题目:Search Insert PositionGiven a sorted array and a target value, return the index if the target is found. If not, return the index where it would be if it were inserted in order.You原创 2014-03-03 15:42:13 · 960 阅读 · 0 评论 -
Leetcode: Max Points on a Line .
题目:Given n points on a 2D plane, find the maximum number of points that lie on the same straight line. 解决:import java.util.HashMap;import java.util.Map;class Point { int x; int y;原创 2014-02-13 16:52:16 · 1426 阅读 · 0 评论 -
First Missing Positive
题目:Given an unsorted integer array, find the first missing positive integer.For example,Given [1,2,0] return 3,and [3,4,-1,1] return 2.Your algorithm should run in O(n) time and uses constan原创 2014-01-02 15:44:18 · 1356 阅读 · 0 评论 -
Jump Game
题目:Given a string containing only digits, restore it by returning all possible valid IP address combinations.For example:Given "25525511135",return ["255.255.11.135", "255.255.111.35"]. (Order原创 2014-01-02 14:41:33 · 711 阅读 · 0 评论 -
Restore IP Addresses
题目:Given a string containing only digits, restore it by returning all possible valid IP address combinations.For example:Given "25525511135",return ["255.255.11.135", "255.255.111.35"]. (Order原创 2014-01-02 11:38:06 · 2076 阅读 · 0 评论 -
寻找发帖水王
是如下的扩展。http://blog.youkuaiyun.com/xiaoding133/article/details/8035183若size个发帖很多的ID,他们的发帖数目都超过了帖子总数目N的1/size,怎么从发贴的ID中快速找出他们的ID?package com.chruan.test.algo;/** * 寻找发帖水王 * @author Chruan * @ver原创 2012-10-10 15:22:08 · 5507 阅读 · 0 评论 -
全排列
#include int n = 0; void swap(int *a, int *b) { int m; m = *a; *a = *b; *b = m; } void perm(int list[], int k, int m) { int i;转载 2012-03-23 16:39:46 · 583 阅读 · 0 评论 -
子数组的最大和
子数组的最大和 public int maxSubsum(int[] a){ int[] b = new int[a.length+1]; for (int i=0;i<a.length+1;i++) b[i]=0; for (int i=0;i<a.length;i++){ for (int j= i;j<a.length;j++) if (b[i+1]原创 2014-03-28 17:07:48 · 713 阅读 · 0 评论