231 Power of Two链接:https://leetcode.com/problems/power-of-two/
问题描述:
Given an integer, write a function to determine if it is a power of two.Credits:
Special thanks to @jianchao.li.fighter for ad...
分类:
其他好文 时间:
2015-07-07 16:59:21
阅读次数:
148
The gray code is a binary numeral system where two successive values differ in only one bit.Given a non-negative integer n representing the total number of bits in the code, print the sequence of gray...
分类:
其他好文 时间:
2015-07-07 16:53:37
阅读次数:
108
1. Two positive integers i and j are considered to be co-prime if there exists no integer greater than 1 that divides them both. Write a function co-....
分类:
其他好文 时间:
2015-07-07 14:42:25
阅读次数:
108
拓扑排序, 输出一种可能的排序结果,207Course Schedule 稍微变化一点即可得到正确答案from collections import defaultdictclass Solution: # @param {integer} numCourses # @param {in...
分类:
其他好文 时间:
2015-07-07 14:28:37
阅读次数:
85
使用 拓扑排序, 使用刚学的defaultdict 哈哈from collections import defaultdictclass Solution: # @param {integer} numCourses # @param {integer[][]} prerequisite...
分类:
其他好文 时间:
2015-07-07 14:26:37
阅读次数:
94
第一个题目是将整数进行反转,这个题实现反转并不难,主要关键点在于如何进行溢出判断。溢出判断再上一篇字符串转整数中已有介绍,本题采用其中的第三种方法,将数字转为字符串,使用字符串比较大小的方法进行比较。代码如下: 1 class Solution { 2 public: 3 int rever...
分类:
其他好文 时间:
2015-07-07 14:24:19
阅读次数:
100
Given an integer, write a function to determine if it is a power of two.
2的幂的二进制表示中,必然只有一个“1”,且不可能为负数。
class Solution {
public:
bool isPowerOfTwo(int n) {
if(n<0)
{//若为负数则...
分类:
其他好文 时间:
2015-07-07 13:08:28
阅读次数:
129
这个题。。是要把字符串转为整数。注意是整数,我看到整数的时候松了一口气,没有小数点的判断应该更好做。而且基本的转化函数我想每个程序员都无法忘记:res=res*10+(str[i]-'0');其实就是这么一句话的事情,然而这个题的通过率只有13%,在200多个题目中排名第五。本想不看提示自己写了一些...
分类:
其他好文 时间:
2015-07-07 12:37:50
阅读次数:
113
Given an integer, write a function to determine if it is a power of two.
题目解析:
求一个数是否是2的幂次方所得。是就返回true,不是就返回false.
方法一:
直接用n%2,结果如果为1,就返回false(n=1除外,因为2的0次幂为1)。
代码如下:
class Solution {
public:
...
分类:
其他好文 时间:
2015-07-07 09:31:52
阅读次数:
132
Given a positive integer, return its corresponding column title as appear in an Excel sheet.For example: 1 -> A 2 -> B 3 -> C ... 26 ->...
分类:
其他好文 时间:
2015-07-07 09:21:14
阅读次数:
233