码迷,mamicode.com
首页 >  
搜索关键字:leetcode count prime    ( 54596个结果
LeetCode - Best Time to Buy and Sell
这道题要求的一个min和一个max,只是这个min所在的位置要在max所在位置的左边。有一种做法是采用蛮力算法,也就是通过从左往右遍历,把每一个元素都当做min,然后再在这个元素的右边找一个最大值,这样得到一个profit,最后求得所有情况中profit的最大值即刻。但是这种做法的时间复杂度是O(n...
分类:其他好文   时间:2014-05-01 10:17:20    阅读次数:287
求一个数的最大素因子(python实现)
首先想到的是,将这个数进行素因子分解,得到所有的因子,然后取最大的。 首先写一个判断一个数是否是素数的方法: #judge a number whether a prime def judgePrime(self,number,pme): if number < 2: ...
分类:编程语言   时间:2014-05-01 09:05:26    阅读次数:3333
Leetcode | Valid Sudoku & Sudoku Solver
判断valid,没有更好的方法,只能brute force。 1 class Solution { 2 public: 3 bool isValidSudoku(vector > &board) { 4 5 int n; 6 for (int...
分类:其他好文   时间:2014-05-01 08:54:28    阅读次数:332
explicit浅谈
在C++中,explicit关键字主要用于防止隐式转换,用于修饰构造函数、复制构造函数。例如有一个类:class A { public: A( int count ) : m_data( count ){} private: int m_data; };int main() { ...
分类:其他好文   时间:2014-05-01 03:03:36    阅读次数:311
国防科大校赛I题: Prime Summation
地址:点击打开链接...
分类:其他好文   时间:2014-04-29 13:44:22    阅读次数:262
Leetcode:Reorder List 单链表重排序
Given a singly linked list L: L0→L1→…→Ln-1→Ln, reorder it to: L0→Ln→L1→Ln-1→L2→Ln-2→… You must do this in-place without altering the nodes' values. For example, Given {1,2,3,4}, reorder it to ...
分类:其他好文   时间:2014-04-29 13:42:21    阅读次数:427
树链剖分教程 & bzoj 1036 [ZJOI2008] 树的统计 Count 题解
【原题】 1036: [ZJOI2008]树的统计Count Time Limit: 10 Sec  Memory Limit: 162 MB Submit: 4465  Solved: 1858 [Submit][Status] Description 一棵树上有n个节点,编号分别为1到n,每个节点都有一个权值w。我们将以下面的形式来要求你对这棵树完成一些操作: I. C...
分类:其他好文   时间:2014-04-29 13:31:21    阅读次数:525
Leetcode:Container with most water 最大蓄水量
Given n non-negative integers a1, a2, ..., an, where each represents a point at coordinate (i, ai). n vertical lines are drawn such that the two endpoints of line i is at (i, ai) and (i, 0). Fin...
分类:其他好文   时间:2014-04-29 13:15:21    阅读次数:415
HDU2138 How many prime numbers
POJ2138 素数判定...
分类:其他好文   时间:2014-04-29 13:14:20    阅读次数:182
Leetcode:Add Binary 二进制相加
Given two binary strings, return their sum (also a binary string). For example, a = "11" b = "1" Return "100". 思路同十进制的大数相加。代码如下: class Solution { public: string addBinary(string a, str...
分类:其他好文   时间:2014-04-29 13:12:20    阅读次数:328
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!