码迷,mamicode.com
首页 >  
搜索关键字:divide and conquer    ( 1165个结果
LeetCode -- Merge k Sorted Lists (Divide and Conquer / PriorityQueue)
Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity. 分支策略:每次归并两个已排好序的链表,直至只剩下一个链表。 public class Solution { public ListNode mergeKLists(List list...
分类:其他好文   时间:2015-03-05 19:33:56    阅读次数:138
Divide Two Integers
Divide two integers without using multiplication, division and mod operator. If it is overflow, return MAX_INT. 思路1:看样只能用减法了,依次减去除数,TOTS,肯定超时。 思路2:每次减去N倍的除数,结果也加上N次,因此我们需要将除数扩大N倍。 int扩展成long防止...
分类:其他好文   时间:2015-03-05 14:55:43    阅读次数:108
基础算法记录——由最大子序列和想到的
这是一个入门级的算法,但它却揭示了计算机算法设计的一些核心思想:枚举与分治递归。这篇文章主要由简单到复杂来解析这一问题,流程大致是:枚举求解(充分利用计算机的计算能力来解决单调复杂问题),算法分析与改进(相对偏移化简枚举法),分治算法(divide-conquer,计算机核心思想之一),递归算法与递...
分类:编程语言   时间:2015-03-01 00:14:24    阅读次数:330
Binary Tree
Binary Tree dfs Traversal-preorder/inorder/postorder-divide&conquer-introduce dfs templatePreorder :Inorder;Postorder:Divide & Conquer :-Merge Sort (a...
分类:其他好文   时间:2015-02-25 11:38:00    阅读次数:123
LeetCode Divide Two Integers
Divide two integers without using multiplication, division and mod operator. If it is overflow, return MAX_INT. 题意:不用乘除和mod运算计算两个数相除。 思路:因为每个数都能表示为二进制,也就是num = a*2^0 + b*2^1....,所以我们只要去判断有哪些2^k就能...
分类:其他好文   时间:2015-02-22 17:23:05    阅读次数:136
归并排序
归并排序(Merge sort)是创建在归并操作上的一种有效的排序算法。该算法是采用分治法(Divide and Conquer)的一个非常典型的应用。算法描述:将待排序数据分为两部分(递归调用归并排序)。对两部分数据进行归并操作。时间复杂度:T(N) = 2 * T(N/2) + cN = 2.....
分类:编程语言   时间:2015-02-16 00:22:14    阅读次数:267
[LeetCode#29]Divide Two Integers
The problem:Divide two integers without using multiplication, division and mod operator.If it is overflow, return MAX_INT.My analysis:The idea behind ...
分类:其他好文   时间:2015-02-13 06:58:04    阅读次数:188
排序算法之快速排序(Quick Sort) -- 适用于Leetcode 75 Sort Colors
Quick Sort使用了Divide and Concur的思想: 找一个基准数, 把小于基准数的数都放到基准数之前, 把大于基准数的数都放到基准数之后Worst case: O(n^2)Average case: O(nlogN)步骤:初始的数组 Array a[]:01234567895173...
分类:编程语言   时间:2015-02-11 09:18:06    阅读次数:122
leetcode[29]Divide Two Integers
Divide two integers without using multiplication, division and mod operator.If it is overflow, return MAX_INT.class Solution {public: int divide(in...
分类:其他好文   时间:2015-02-10 14:46:30    阅读次数:174
leetcode:Divide Two Integers
一、 题目 不使用乘法、除法、求余运算实现除法运算,除数和被除数、结果都是用int型。 如果溢出就返回MAX_INT。 二、 分析 看到题目后我立马想到了计算机组成原理中的一位除法和二位除法,不过想想在这里实现起来又是太麻烦了。 那就先试试暴力法吧,被除数 - 除数 = ???一直减减减直到小于等于0,想想自己都觉得超时。。。如下,果然超时  class Solution { publ...
分类:其他好文   时间:2015-02-10 11:15:25    阅读次数:135
1165条   上一页 1 ... 94 95 96 97 98 ... 117 下一页
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!