码迷,mamicode.com
首页 >  
搜索关键字:divide    ( 1127个结果
Divide Two Integers
用减法可能会超时,但可以用二分 class Solution { public:     int divide(int d1, int d2) {//       d1/d2         if(d1==0)             return 0;         if(d2==1)             return d1;         if(d2==-1)    ...
分类:其他好文   时间:2014-06-29 07:22:02    阅读次数:208
白话经典算法系列之五 归并排序的实现
归并排序是建立在归并操作上的一种有效的排序算法。该算法是採用分治法(Divide and Conquer)的一个很典型的应用。首先考虑下怎样将将二个有序数列合并。这个很easy,仅仅要从比較二个数列的第一个数,谁小就先取谁,取了后就在相应数列中删除这个数。然后再进行比較,假设有数列为空,那直接将还有...
分类:其他好文   时间:2014-06-11 21:52:36    阅读次数:289
LeetCode:Divide Two Integers
Divide two integers without using multiplication, division and mod operator. 其实刚开始看到这道题的时候,感觉应该是略简单。但真正开始写的时候发现了很多错误。 最开始的想法就是divisor一个一个加上去直到大于divide...
分类:其他好文   时间:2014-06-11 12:17:22    阅读次数:274
[leetcode]Divide Two Integers @ Python
原题地址:https://oj.leetcode.com/problems/divide-two-integers/题意:Divide two integers without using multiplication, division and mod operator.解题思路:不许用乘、除和求...
分类:编程语言   时间:2014-06-10 21:43:00    阅读次数:267
leetcode——Divide Two Integers 不用乘除取余操作求除法(AC)
题目只有简单的一句话,看起来可真简单啊,呵呵,假象。这个题目的难点在于对时间效率的限制和边界值的测试。第一印象肯定是循环一个个把因子从被除数中减去不久行了么,可是对于比如INT_MAX/1或者INT_MIN/1之类的执行时间长的可怕,会超出时间限制。改善时间效率的思路是参考网上别人代码,将因子不断乘以2(可以通过移位实现,同时结果也从1开始不断移位加倍),然后和被除数比较,等到大于被除数一半了,就从被除数中减去,将因子个数叠加入结果中。然后在剩下的被除数中采用同样的方法减去小于其一半的因子和,循环往复。我在...
分类:其他好文   时间:2014-06-10 06:51:06    阅读次数:209
第四章 分治策略 4.2 矩阵乘法的Strassen算法
package chap04_Divide_And_Conquer;import static org.junit.Assert.*;import java.util.Arrays;import org.junit.Test;/** * 矩阵相乘的算法 * * @author xiaojintao....
分类:其他好文   时间:2014-06-09 16:12:24    阅读次数:273
LeetCode --- Rotate Image
题目链接题意: 给出 n * n的矩阵,要求将矩阵顺时针旋转90°(不使用额外空间) 1 /* 2 Basically, divide the array into 4 along the diagonals, 3 then for each element in the top ...
分类:其他好文   时间:2014-06-09 15:28:14    阅读次数:280
第四章 分治策略 4.1 最大子数组问题(自己想的,不知道是不是减治法)
package chap04_Divide_And_Conquer;import static org.junit.Assert.*;import java.util.Arrays;import org.junit.Test;/** * 算反导论第四章 4.1 最大子数组 * * @author ....
分类:其他好文   时间:2014-06-07 20:21:38    阅读次数:212
projecteuler---->problem=21----Amicable numbers
Let d(n) be defined as the sum of proper divisors of n (numbers less than n which divide evenly into n). If d(a) = b and d(b) = a, where a b, then a and b are an amicable pair and each of a and b...
分类:其他好文   时间:2014-06-07 13:40:53    阅读次数:226
【Leetcode】Divide Two Integers
Divide two integers without using multiplication, division and mod operator. 1 class Solution { 2 public: 3 int divide(int dividend, int divisor) ...
分类:其他好文   时间:2014-06-06 17:40:07    阅读次数:193
1127条   上一页 1 ... 109 110 111 112 113 下一页
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!