
leetcode
junlon2006
Coding for fun.
展开
-
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.点击打开链接int getSum(int a, int b) { int sum = a;原创 2017-01-03 16:24:33 · 234 阅读 · 0 评论 -
Missing Number
https://leetcode.com/problems/missing-number/?tab=DescriptionGiven an array containing n distinct numbers taken from 0, 1, 2, ..., n, find the one that is missing from the array.For exampl原创 2017-03-07 19:13:40 · 411 阅读 · 0 评论 -
Base 7
https://leetcode.com/problems/base-7/?tab=DescriptionGiven an integer, return its base 7 string representation.Example 1:Input: 100Output: "202"Example 2:Input: -7Output:原创 2017-03-07 18:58:02 · 314 阅读 · 0 评论 -
Keyboard Row
https://leetcode.com/problems/keyboard-row/?tab=DescriptionGiven a List of words, return the words that can be typed using letters of alphabet on only one row's of American keyboard like the ima原创 2017-03-07 16:54:39 · 303 阅读 · 0 评论 -
约瑟夫环问题
输入: total:参与的总数量; selector:出局的号码。输出:逐个出局的详细列表,输出最后的winner。 void joserf(int total, int selector){ ListNode head, *p1, *p2; int sel = selector; if(total <= 0) return; if(selector =原创 2017-02-17 10:51:42 · 408 阅读 · 0 评论 -
Valid Palindrome
https://leetcode.com/problems/valid-palindrome/?tab=DescriptionGiven a string, determine if it is a palindrome, considering only alphanumeric characters and ignoring cases.For example,"A m原创 2017-03-09 11:12:26 · 175 阅读 · 0 评论 -
Detect Capital
https://leetcode.com/problems/detect-capital/?tab=DescriptionGiven a word, you need to judge whether the usage of capitals in it is right or not.We define the usage of capitals in a word to原创 2017-03-07 17:21:39 · 263 阅读 · 0 评论 -
Reverse Vowels of a String
https://leetcode.com/problems/reverse-vowels-of-a-string/?tab=DescriptionWrite a function that takes a string as input and reverse only the vowels of a string.Example 1:Given s = "hello",原创 2017-03-08 13:34:56 · 213 阅读 · 0 评论 -
Maximum Subarray
https://leetcode.com/problems/maximum-subarray/?tab=DescriptionFind the contiguous subarray within an array (containing at least one number) which has the largest sum.For example, given th原创 2017-03-08 10:27:41 · 202 阅读 · 0 评论 -
一个人爬楼梯,楼梯共20层,一人一步可以走一层或两层,共多少种走法?
这个问题,是一个简单的递归问题。1、走1层,有一种走法,一步走一层。2、走2层,有两种走法,可以一步一层走,或一步走两层。3、走N层,的方法有多少种呢?走到N层只有两种可能,就是N-1层走一步(1步一层)到N层,或者是N-2层走1步(1步两层)。4、a[N] = a[N-1] + a[N-2];#include int getUpstailTypes(int n){ if原创 2017-01-04 11:03:45 · 13566 阅读 · 0 评论 -
Sum of Left Leaves
Find the sum of all left leaves in a given binary tree.Example: 3 / \ 9 20 / \ 15 7There are two left leaves in the binary tree, with values 9 and 15 respectively. Retur原创 2017-02-12 12:20:15 · 229 阅读 · 0 评论 -
Longest Palindrome
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原创 2017-02-12 09:57:16 · 276 阅读 · 0 评论 -
Flatten Binary Tree to Linked List
Given a binary tree, flatten it to a linked list in-place.For example,Given 1 / \ 2 5 / \ \ 3 4 6The flattened tree should look like: 1原创 2017-01-20 16:18:14 · 173 阅读 · 0 评论 -
Island Perimeter
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 completely原创 2016-12-30 16:14:17 · 277 阅读 · 1 评论 -
Fizz Buzz
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”.原创 2016-12-30 15:39:42 · 197 阅读 · 0 评论 -
Hamming Distance
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原创 2016-12-30 09:19:18 · 225 阅读 · 0 评论 -
Pascal's Triangle II
Given an index k, return the kth row of the Pascal's triangle.For example, given k = 3,Return [1,3,3,1].https://leetcode.com/problems/pascals-triangle-ii//** * Return an array of size原创 2016-12-29 14:51:29 · 197 阅读 · 0 评论 -
Merge Two Sorted Lists
https://leetcode.com/problems/merge-two-sorted-lists/Merge two sorted linked lists and return it as a new list. The new list should be made by splicing together the nodes of the first two list原创 2016-12-29 10:32:58 · 191 阅读 · 0 评论 -
Palindrome Number
https://leetcode.com/problems/palindrome-number/?tab=DescriptionDetermine whether an integer is a palindrome. Do this without extra space.//method 1bool isPalindrome(int x) { int y = 0, tmp原创 2017-03-07 19:52:43 · 208 阅读 · 0 评论