
LeetCode
Davy_Joe
编程也是一门艺术,只是实现艺术的方式不同而已!
展开
-
LeetCode 169. Majority Element(Java)
题目: Given an array of size n, find the majority element. The majority element is the element that appears more than ⌊ n/2 ⌋ times.You may assume that the array is non-empty and the majority element al原创 2016-12-06 19:30:19 · 437 阅读 · 0 评论 -
LeetCode 371. Sum of Two Integers
原题: Calculate the sum of two integers a and b, but you are not allowed to use the operator + and -.Example: Given a = 1 and b = 2, return 3.题意: 计算两个整数a和b的和,但是你不允许使用操作符+和-。例子: 给定a=1和b=2,返回3。思路: 利用两原创 2017-02-03 13:21:54 · 448 阅读 · 0 评论 -
LeetCode 136. Single Number(Java)
原题: 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 ext原创 2017-01-25 15:56:43 · 498 阅读 · 0 评论 -
LeetCode 492. Construct the Rectangle(Java)
原题: For a web developer, it is very important to know how to design a web page’s size. So, given a specific rectangular web page’s area, your job by now is to design a rectangular web page, whose leng原创 2017-01-23 23:02:14 · 1345 阅读 · 0 评论 -
LeetCode 448. Find All Numbers Disappeared in an Array(Java)
原题: Given an array of integers where 1 ≤ a[i] ≤ n (n = size of array), some elements appear twice and others appear once.Find all the elements of [1, n] inclusive that do not appear in this array.Coul原创 2017-01-23 22:38:15 · 763 阅读 · 0 评论 -
LeetCode 292. Nim Game(Java)
原题: You are playing the following Nim Game with your friend: There is a heap of stones on the table, each time one of you take turns to remove 1 to 3 stones. The one who removes the last stone will be原创 2017-01-22 21:34:38 · 485 阅读 · 0 评论 -
LeetCode 463. Island Perimeter(Java)
原题: You are given a map in form of a two-dimensional integer grid where 1 represents land and 0 represents water. Grid cells are connected horizontally/vertically (not diagonally). The grid is complet原创 2017-01-21 11:52:02 · 1124 阅读 · 0 评论 -
LeetCode 344. Reverse String(Java)
原题: Write a function that takes a string as input and returns the string reversed.Example: Given s = “hello”, return “olleh”.题意: 写一个方法可以将输入的字符串反转并返回。思路: 1.将字符串转化为字符数组; 2.对字符数组关于中间对称的元素进行交换; 3.将字符原创 2017-01-19 22:25:44 · 478 阅读 · 0 评论 -
LeetCode 485. Max Consecutive Ones(Java)
原题: Given a binary array, find the maximum number of consecutive 1s in this array.Example 1: Input: [1,1,0,1,1,1] Output: 3 Explanation: The first two digits or the last three digits are consecutiv原创 2017-01-19 21:45:33 · 1050 阅读 · 0 评论 -
LeetCode 2. Add Two Numbers(Java)
原题: You are given two non-empty linked lists representing two non-negative integers. The digits are stored in reverse order and each of their nodes contain a single digit. Add the two numbers and retu原创 2017-01-14 23:33:58 · 515 阅读 · 0 评论 -
LeetCode 412. Fizz Buzz(Java)
原题: Write a program that outputs the string representation of numbers from 1 to n.But for multiples of three it should output “Fizz” instead of the number and for the multiples of five output “Buzz”.原创 2017-01-19 22:13:57 · 1055 阅读 · 0 评论 -
LeetCode 476. Number Complement(Java)
原题: Given a positive integer, output its complement number. The complement strategy is to flip the bits of its binary representation.Note: The given integer is guaranteed to fit within the range of a原创 2017-01-19 21:20:34 · 896 阅读 · 0 评论 -
LeetCode 1. Two Sum(Java)
原题: Given an array of integers, return indices of the two numbers such that they add up to a specific target.You may assume that each input would have exactly one solution.Example: Given nums = [2, 7原创 2017-01-13 23:07:44 · 323 阅读 · 0 评论 -
LeetCode 461. Hamming Distance(Java)
原题: The Hamming distance between two integers is the number of positions at which the corresponding bits are different.Given two integers x and y, calculate the Hamming distance.Note: 0 ≤ x, y < 231.原创 2017-01-07 08:12:52 · 633 阅读 · 0 评论 -
LeetCode 350. Intersection of Two Arrays II(Java)
原题: Given two arrays, write a function to compute their intersection.Example: Given nums1 = [1, 2, 2, 1], nums2 = [2, 2], return [2, 2].Note: Each element in the result should appear as many times a原创 2016-12-07 23:59:30 · 450 阅读 · 0 评论 -
LeetCode 217. Contains Duplicate(Java)
原题: 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 elemen原创 2016-12-07 23:25:32 · 395 阅读 · 0 评论 -
LeetCode 409. Longest Palindrome(Java)
题目: Given a string which consists of lowercase or uppercase letters, find the length of the longest palindromes that can be built with those letters.This is case sensitive, for example “Aa” is not con原创 2016-12-06 20:12:38 · 340 阅读 · 0 评论