
LeetCode
文章平均质量分 60
小麦成长记
这个作者很懒,什么都没留下…
展开
-
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].Note:Each element in the result must be unique.The res原创 2017-05-29 18:07:30 · 200 阅读 · 0 评论 -
LeetCode 409. 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-05-26 20:49:34 · 463 阅读 · 1 评论 -
LeetCode 520:Detect Capital
Given 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 be right when one of the following cases holds:All letters in t原创 2017-05-26 18:25:50 · 323 阅读 · 0 评论 -
LeetCode 136:Single Number(异或操作)
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-05-26 16:54:35 · 227 阅读 · 0 评论 -
LeetCode 485:Max Consecutive Ones(连续1的最大个数,边界条件)
Given a binary array, find the maximum number of consecutive 1s in this array.Example 1:Note:设置两个变量cons和max,分别用来统计当前连续1的个数和最大1的个数。当元素的值等于1的时候,当前连续1的个数增加1,并且判断cons是否大于max,若cons>max,max=co原创 2017-05-26 16:18:51 · 373 阅读 · 0 评论 -
LeetCode 292:Nim Game(尼姆游戏)
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 the原创 2017-05-26 15:51:48 · 633 阅读 · 0 评论 -
LeetCode 463: 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 co原创 2017-05-25 22:07:36 · 680 阅读 · 0 评论 -
LeetCode 344: Reverse String (字符串翻转)
Write a function that takes a string as input and returns the string reversed.Example:Given s = "hello", return "olleh".Note:1.注意空间复杂度,不需要重新分配内存,直接在原字符串上进行操作。 2.swap()函数的使用, swap函数原型如下:原创 2017-05-25 16:03:33 · 342 阅读 · 3 评论 -
LeetCode 496: Next Greater Element I (下一个大的元素)
You are given two arrays (without duplicates) nums1 and nums2 where nums1’s elements are subset of nums2. Find all the next greater numbers for nums1's elements in the corresponding places of nums原创 2017-05-25 20:37:50 · 413 阅读 · 3 评论 -
LeetCode 389. Find the Difference(异或)
Given two strings s and t which consist of only lowercase letters.String t is generated by random shuffling string s and then add one more letter at a random position.Find the letter that was原创 2017-05-31 15:47:20 · 269 阅读 · 0 评论 -
LeetCode 599. Minimum Index Sum of Two Lists(map,unordered_map)
Suppose Andy and Doris want to choose a restaurant for dinner, and they both have a list of favorite restaurants represented by strings.You need to help them find out their common interest with th原创 2017-05-31 19:53:03 · 620 阅读 · 0 评论 -
LeetCode 448. Find All Numbers Disappeared in an Array(查找数组中没有出现的数字)
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.原创 2017-05-26 21:06:27 · 259 阅读 · 0 评论 -
LeetCode 242. Valid Anagram(字谜)
Total Accepted: 153072Total Submissions: 333862Difficulty: EasyContributor: LeetCodeGiven two strings s and t, write a function to determine if t is an anagram of s.For example,s = "anagram"原创 2017-05-26 21:58:04 · 360 阅读 · 0 评论 -
LeetCode 455. Assign Cookies(数组,排序)
Assume you are an awesome parent and want to give your children some cookies. But, you should give each child at most one cookie. Each child i has a greed factor gi, which is the minimum size of a c原创 2017-05-29 17:34:10 · 242 阅读 · 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.思路:如果两个节点中有一原创 2017-05-29 11:02:42 · 359 阅读 · 0 评论 -
LeetCode 404. 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-05-29 10:23:15 · 210 阅读 · 0 评论 -
LeetCode 167. Two Sum II - Input array is sorted(有序数组夹逼法)
Total Accepted: 74198Total Submissions: 157252Difficulty: EasyContributor: LeetCodeGiven an array of integers that is already sorted in ascending order, find two numbers such that they add up原创 2017-05-29 09:46:42 · 308 阅读 · 0 评论 -
LeetCode 283. Move Zeroes
Given an array nums, write a function to move all 0'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 you原创 2017-05-28 22:31:47 · 193 阅读 · 0 评论 -
LeetCode 258. Add Digits(1+(n-1)%9)
Given a non-negative integer num, repeatedly add all its digits until the result has only one digit.For example:Given num = 38, the process is like: 3 + 8 = 11, 1 + 1 = 2. Since 2 has on原创 2017-05-28 22:06:51 · 224 阅读 · 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&b得到进位,然后将“进位”左移与“和”相异或;循环上述操作。C原创 2017-05-28 21:09:54 · 233 阅读 · 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 ...原创 2017-05-27 20:42:05 · 240 阅读 · 0 评论 -
LeetCode 387. First Unique Character in a String(unordered_map元素顺序杂乱性)
Given a string, find the first non-repeating character in it and return it's index. If it doesn't exist, return -1.Examples:s = "leetcode"return 0.s = "loveleetcode",return 2.Note: You m原创 2017-05-27 20:09:07 · 317 阅读 · 0 评论 -
LeetCode 169. Majority Element
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原创 2017-05-27 12:33:35 · 181 阅读 · 0 评论 -
LeetCode 383. Ransom Note
Given an arbitrary ransom note string and another string containing letters from all the magazines, write a function that will return true if the ransom note can be constructed from the magazines ; ot原创 2017-06-01 09:50:08 · 302 阅读 · 0 评论