码迷,mamicode.com
首页 >  
搜索关键字:in-place    ( 1961个结果
将矩阵中值为0的元素所在的行和列设置为0, in-place O(1)space O(mn) time
将矩阵中值为0的元素所在的行和列设置为0, in-place O(1)space O(mn) time 使用O(m+n)space 的方案比较容易想到...
分类:其他好文   时间:2015-04-09 22:00:53    阅读次数:128
算法导论--第二章、插入排序
1. 插入排序类似于整理扑克牌(排列好顺序的扑克和待排序的扑克);2. 插入排序(INSERTION-SORT)参数是一个数组A[1..n]共n个数,输入的各个数字原地排序(sorted in place),分为排好序的和待排序的,每次取一个待排序元素,找到插入的位置,插入已排好序的部分中。元素取完...
分类:编程语言   时间:2015-04-09 17:01:05    阅读次数:132
leetcode || 73、Set Matrix Zeroes
problem: Given a m x n matrix, if an element is 0, set its entire row and column to 0. Do it in place. click to show follow up. Follow up: Did you use extra space? A straight forward ...
分类:其他好文   时间:2015-04-09 12:00:06    阅读次数:138
LeetCode --- 92. Reverse Linked List II
题目链接:Reverse Linked List II Reverse a linked list from position m to n. Do it in-place and in one-pass. For example: Given 1->2->3->4->5->NULL, m = 2 and n = 4, return 1->4->3->2->5->NULL. Note: ...
分类:其他好文   时间:2015-04-09 11:57:57    阅读次数:209
Flatten Binary Tree to Linked List--LeetCode
题目: Given a binary tree, flatten it to a linked list in-place. For example, Given 1 / 2 5 / \ 3 4 6 The flattened tree should look like: ...
分类:其他好文   时间:2015-04-09 10:38:07    阅读次数:128
LeetCode48/189 Rotate Image/Rotate Array
一:Rotate Image 题目: You are given an n x n 2D matrix representing an image. Rotate the image by 90 degrees (clockwise). Follow up: Could you do this in-place? 链接:https://leetcode.com/prob...
分类:其他好文   时间:2015-04-08 19:54:55    阅读次数:141
Rotate Image --LeetCode
题目: You are given an n x n 2D matrix representing an image. Rotate the image by 90 degrees (clockwise). Follow up: Could you do this in-place? 思路:使用最基本的方法,递归,但是有空间复杂度 #include #inc...
分类:其他好文   时间:2015-04-07 19:43:35    阅读次数:102
奔走在算法的大路上(一)排序之插入排序
插入排序(Insertion Sort)是一种简单直观的排序算法。它的工作原理是通过构建有序序列,对于未排序数据,在已排序序列中从后向前扫描,找到相应位置并插入。插入排序在实现上,通常采用in-place排序(即只需用到O(1)的额外空间的排序),因而在从后向前扫描过程中,需要反复把已排序元素逐步向后挪位,为最新元素提供插入空间。 其原理我感觉用一张图说明时最好的了 源码 packa...
分类:编程语言   时间:2015-04-07 15:41:10    阅读次数:147
Reverse Linked List II
Reverse a linked list from positionmton. Do it in-place and in one-pass.For example:Given1->2->3->4->5->NULL,m= 2 andn= 4,return1->4->3->2->5->NULL.No...
分类:其他好文   时间:2015-04-07 11:39:39    阅读次数:123
Flatten Binary Tree to Linked List
Flatten Binary Tree to Linked List Given a binary tree, flatten it to a linked list in-place....
分类:其他好文   时间:2015-04-07 09:58:30    阅读次数:135
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!