
algorithm
千里之外z
人生几何?
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
Permutation Sequence
The set [1,2,3,…,n] contains a total of n! unique permutations.By listing and labeling all of the permutations in order, We get the following sequence (ie, for n = 3):“123” “132” “213” “231” “312”原创 2017-07-01 12:46:48 · 216 阅读 · 0 评论 -
Rotate List
Given a list, rotate the list to the right by k places, where k is non-negative.For example: Given 1->2->3->4->5->NULL and k = 2, return 4->5->1->2->3->NULL.题目的意思就是将倒数K个数翻转到前面去 用正常的思路我试过没问题(先遍历求得总长原创 2017-07-01 14:37:24 · 229 阅读 · 0 评论 -
Unique Paths
A robot is located at the top-left corner of a m x n grid (marked ‘Start’ in the diagram below).The robot can only move either down or right at any point in time. The robot is trying to reach the botto原创 2017-07-03 10:47:58 · 412 阅读 · 0 评论 -
组合的递归与非递归
从n数组中选取m个数#include<iostream>#include<string>#include<vector>using namespace std;//递归写法//从n个元素中选取m个 排列有序 123!=321void Print(int a[],int b[], int n, int m,vector<int>res){ if (m == 0) {原创 2017-08-07 17:41:26 · 1126 阅读 · 0 评论 -
智能指针
问题来源:new 出来的对象一般要手动delete,如果发生异常导致程序(函数)过早退出从而没有执行delete,造成内存泄露。智能指针可以解决这个问题,它是将基本类型指针封装成类对象指针(这个类是个模板),并在析构函数里编写delete语句,删除指针指向的内存空间。对于编译器来说,智能指针实际上是个栈对象,在栈对象生命周期结束的时候,会调用析构函数。STL提供了四个类smart_ptr:auto_原创 2017-08-09 20:43:18 · 291 阅读 · 0 评论 -
打印1到最大的n位数
考虑大数问题,用数组表示,要做两件事:数组加一,输出数组bool IsAdd(int a[],int n){ int flag = 0; for (int i = n; i >= 0; i--) { if (i == n) { int tmp = a[i] + flag + 1; (最后一原创 2017-08-02 19:52:16 · 189 阅读 · 0 评论 -
Decode Ways
A ->1 B->2 . . . Z ->26例: 12 可以表示AB和L,两种方法 求任意一个字符串可以表示的方法数思路:动态规划 字符串s a[n]与a[n-1]和a[n-2]有关,a[n]是以s[n]为结尾的串的方法总数 例如:1124 中a[4]的解法可以是((1..3),4)也可以是((1..1),24) 即a[4]=a[4-1]+a[4-2] 里面还有一些划分,具体原创 2017-08-18 11:18:29 · 206 阅读 · 0 评论 -
Sort List
Sort a linked list in O(n log n) time using constant space complexity. 链表排序思路:归并排序// 查找中间的元素 用快慢表方法,一个表走一步,一个表走两步,直到块表结束ListNode * GetMid(ListNode * head){ ListNode *p1 = head; ListNode *p2原创 2017-08-21 19:56:05 · 185 阅读 · 0 评论 -
Single Number II
Given an array of integers, every element appears three times except for one, which appears exactly once. Find that single one.Note: Your algorithm should have a linear runtime complexity. Could you i原创 2017-08-25 18:50:12 · 209 阅读 · 0 评论