
Math
pengweixuan008
这个作者很懒,什么都没留下…
展开
-
204.Count Primes(1-N中,素数的个数)
题目:Count the number of prime numbers less than a non-negative number, n.代码:public class Solution { public int countPrimes(int n) { boolean [] a = new boolean[n]; int cou原创 2015-07-28 16:20:25 · 257 阅读 · 0 评论 -
231.Power of Two(2的N次方)
Given an integer, write a function to determine if it is a power of two.方法:如果这个数是2的倍数(n%2==0),将这个数除以二(n /=2 ),循环上述操作,最后n==1返回true代码:public class Solution { public boolean isPowerOfTwo原创 2015-07-28 14:30:15 · 304 阅读 · 0 评论 -
连续子数组的最大和
public Integer findGreatestSum(int[] arr){ if(arr.length ==0) return null; int greatest = 0x80000000; int curSum = 0; for(int i转载 2015-08-09 17:01:22 · 280 阅读 · 0 评论 -
171.Excel Sheet Column Number (AB=28)
Given a column title as appear in an Excel sheet, return its corresponding column number.For example: A -> 1 B -> 2 C -> 3 ... Z -> 26 AA -> 27 AB -> 28 public class原创 2015-07-29 12:01:43 · 204 阅读 · 0 评论 -
168.Excel Sheet Column Title(28 -> AB)
Given a positive integer, return its corresponding column title as appear in an Excel sheet.For example: 1 -> A 2 -> B 3 -> C ... 26 -> Z 27 -> AA 28 -> AB 代码:publ原创 2015-07-29 14:02:22 · 235 阅读 · 0 评论 -
202.Happy Number
A happy number is a number defined by the following process: Starting with any positive integer, replace the number by the sum of the squares of its digits, and repeat the process until the number equ原创 2015-07-29 11:06:49 · 264 阅读 · 0 评论 -
1.Two Sum (数组中两个数之和为n)
Given an array of integers, find two numbers such that they add up to a specific target number.Input: numbers={2, 7, 11, 15}, target=9Output: index1=1, index2=2代码:public class Solution原创 2015-08-03 14:27:57 · 444 阅读 · 0 评论 -
13.Roman to Integer (罗马数字转成整数)
public class Solution { public int romanToInt(String s) { char[] symbol = { 'I', 'V', 'X', 'L', 'C', 'D', 'M' }; int[] val = { 1, 5, 10, 50, 100, 500, 1000 }; Map map =原创 2015-08-03 14:32:24 · 279 阅读 · 0 评论