全站日记 标签: leetcode

题目为:Given an array of integers, every element appears twice except for one. Find that single one. Note: Your algorithm should have a linear runtime complexity. Could you implement it without using extra memory? 一般情况下,可将题目中...
Given numRows, generate the first numRows of Pascal's triangle. For example, given numRows = 5, Return [ [1], [1,1], [1,2,1], [1,3,3,1], [1,4,6,4,1] ] public class Solution { public List<List<Integer>> generate(int numRows) { List<List<I...
public class Solution { public int numTrees(int n) { // Start typing your Java solution below // DO NOT write main() function if(n==0||n==1) return 1; int[] f = new int[n+1]; f[0] = 1; f[1] = 1; for(int i=2;i<=n;i++) { for(int j=0;j<i;j+...
题目:Ugly Number是质因数仅为2、3、5的非负数,给一个数,要判断它是不是Ugly Number。 伪代码: def f(x): if x除以2或3或5,中间有一个等于1: (1) x是Ugly Number 结束 else: if x除以2、3、5中间某一个数得到整数: 将该整数...
public class Solution { public int[][] generateMatrix(int n) { // Start typing your Java solution below // DO NOT write main() function int[][] res = new int[n][n]; if(n<=0) return res; int total = n/2;//计算层数 int cnt = 1; for(int k=0...
Difficulty: Medium Given a range [m, n] where 0 <= m <= n <= 2147483647, return the bitwise AND of all numbers in this range, inclusive. For example, given the range [5, 7], you should return 4. public: int rangeBitwiseAnd(int m, int n) ...
def fizzbuzz(n): for i in range(1,n+1): if (i%3==0)and(i%5!=0): print("Fizz") elif (i%3!=0)and(i%5==0): print("Buzz") elif (i%3==0)and(i%5==0): print("FizzBuzz") else: print(i) return fizzbuzz(15)
我的leetcode 代码。 C++ 代码在文件夹*c++/*中,文件名为题目链接*后缀.cpp*,如:https://oj.leetcode.com/problems/lru-cache/ 对应的代码文件为*lru-cache.cpp* ### About This Repo * 所有代码均为原创,可随意转载、使用、修改,请标明出处。 * 代码...    (1回应)

leetcode 3Sum

coding_man coding_man 2013-10-17 22:48:05
public class Solution { public ArrayList<ArrayList<Integer>> threeSum(int[] num) { // Note: The Solution object is instantiated only once and is reused by each test case. ArrayList<ArrayList<Integer>> resi = new ArrayList<ArrayList<Integ...

2噗噗噗噗噗

库不酷 库不酷 2018-12-11 18:43:43
发发发你
<前页 1 2 3 4 5 ... 9 10 后页>

查看其它标签的日记: