Leetcode
明瑶
这个作者很懒,什么都没留下…
展开
-
Leetcode 343. Integer Break
Given a positive integer n, break it into the sum of at least two positive integers and maximize the product of those integers. Return the maximum product you can get.For example, given n = 2, retur原创 2016-05-11 11:54:43 · 289 阅读 · 0 评论 -
Leetcode 231. Power of Two
Given an integer, write a function to determine if it is a power of two.方法一:public class Solution { public boolean isPowerOfTwo(int n) { if(n if(Integer.bitCount(n) == 1原创 2016-05-19 22:21:12 · 319 阅读 · 0 评论 -
Leetcode 191. Number of 1 Bits
Write a function that takes an unsigned integer and returns the number of ’1' bits it has (also known as theHamming weight).For example, the 32-bit integer ’11' has binary representation00000000原创 2016-05-19 11:14:14 · 332 阅读 · 0 评论 -
Leetcode 326. Power of Three
Given an integer, write a function to determine if it is a power of three.Follow up:Could you do it without using any loop / recursion?解:public class Solution { public boolean isPow原创 2016-05-19 00:06:21 · 388 阅读 · 0 评论 -
Leetcode 100. Same Tree
Given two binary trees, write a function to check if they are equal or not.Two binary trees are considered equal if they are structurally identical and the nodes have the same value./** * Definit原创 2016-05-12 21:23:44 · 290 阅读 · 0 评论 -
Leetcode 242. Valid Anagram
Given two strings s and t, write a function to determine ift is an anagram of s.For example,s = "anagram", t = "nagaram", return true.s = "rat", t = "car", return false.public class Soluti原创 2016-05-13 13:07:12 · 358 阅读 · 0 评论 -
Leetcode 171. Excel Sheet Column Number
Related to question Excel Sheet Column TitleGiven a column title as appear in an Excel sheet, return its corresponding column number.For example: A -> 1 B -> 2 C -> 3 ... Z原创 2016-05-13 14:47:23 · 284 阅读 · 0 评论 -
Leetcode 206. Reverse Linked List
Reverse a singly linked list.可以将原来的list的节点依次尾插另一个list列表尾部递归/** * Definition for singly-linked list. * public class ListNode { * int val; * ListNode next; * ListNode(in原创 2016-05-14 22:50:56 · 290 阅读 · 0 评论 -
Leetcode 237. Delete Node in a Linked List
Write a function to delete a node (except the tail) in a singly linked list, given only access to that node.Supposed the linked list is 1 -> 2 -> 3 -> 4 and you are given the third node with value原创 2016-05-12 20:33:36 · 298 阅读 · 0 评论 -
Leetcode 104. Maximum Depth of Binary Tree
Given a binary tree, find its maximum depth.The maximum depth is the number of nodes along the longest path from the root node down to the farthest leaf node./** * Definition for a binar原创 2016-05-12 00:16:32 · 283 阅读 · 0 评论 -
字符串反转--Leetcode Reverse String
Write a function that takes a string as input and returns the string reversed.Example:Given s = "hello", return "olleh".public class Solution { public String reverseString(String s)原创 2016-04-23 18:56:47 · 319 阅读 · 0 评论 -
Leetcode 83. Remove Duplicates from Sorted List
Given a sorted linked list, delete all duplicates such that each element appear onlyonce.For example,Given 1->1->2, return 1->2.Given 1->1->2->3->3, return 1->2->3./** * Definition for原创 2016-05-28 18:58:40 · 322 阅读 · 0 评论 -
Leetcode 350. Intersection of Two Arrays II
Given two arrays, write a function to compute their intersection.Example:Given nums1 = [1, 2, 2, 1], nums2 = [2, 2], return[2, 2].public class Solution { public int[] intersect(int[] n原创 2016-05-28 17:44:45 · 324 阅读 · 0 评论 -
Leetcode 217. Contains Duplicate
Given an array of integers, find if the array contains any duplicates. Your function should return true if any value appears at least twice in the array, and it should return false if every element is原创 2016-05-27 20:17:53 · 308 阅读 · 0 评论 -
Leetcode 169. Majority Element
Given an array of size n, find the majority element. The majority element is the element that appearsmore than ⌊ n/2 ⌋ times.You may assume that the array is non-empty and the majority element alw原创 2016-05-27 19:56:05 · 344 阅读 · 0 评论 -
LeetCode 349. Intersection of Two Arrays
Given two arrays, write a function to compute their intersection.Example:Given nums1 = [1, 2, 2, 1], nums2 = [2, 2], return[2].public class Solution { public int[] intersection(int[] n原创 2016-05-27 18:22:55 · 402 阅读 · 0 评论 -
L1-003. 个位数统计
给定一个k位整数N = dk-1*10k-1 + ... + d1*101 + d0 (0ik-1>0),请编写程序统计每种不同的个位数字出现的次数。例如:给定N = 100311,则有2个0,3个1,和1个3。输入格式:每个输入包含1个测试用例,即一个不超过1000位的正整数N。输出格式:对N中每一种不同的个位数字,以D:M的格式在一行中输出该位数字D及其在N中出现的次数M。要求原创 2016-05-25 23:04:25 · 897 阅读 · 0 评论 -
Vector删除指定元素
Given an array nums, write a function to move all0's to the end of it while maintaining the relative order of the non-zero elements.For example, given nums = [0, 1, 0, 3, 12], after calling your f原创 2016-05-12 17:48:52 · 954 阅读 · 0 评论 -
Leetcode 263. Ugly Number
Write a program to check whether a given number is an ugly number.Ugly numbers are positive numbers whose prime factors only include2, 3, 5. For example, 6, 8 are ugly while 14 is not ugly since i原创 2016-05-21 13:06:04 · 337 阅读 · 0 评论