leetcode
文章平均质量分 55
jianingkid
这个作者很懒,什么都没留下…
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
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 constru原创 2016-08-13 10:21:33 · 267 阅读 · 0 评论 -
627. Swap Salary+编程中早晚用到的|、||、&、&&、异或、~、!运算
Given a table salary, such as the one below, that has m=male and f=female values. Swap all f and m values (i.e., change all f values to m and vice versa) with a single update query and no intermedia转载 2017-07-12 20:24:58 · 709 阅读 · 0 评论 -
412. Fizz Buzz+String与int类型转化
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-07-13 09:12:45 · 311 阅读 · 0 评论 -
496. Next Greater Element I+附hashmap用法
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-07-13 09:33:58 · 220 阅读 · 0 评论 -
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 completely转载 2017-07-13 20:40:35 · 173 阅读 · 0 评论 -
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-07-14 09:26:38 · 189 阅读 · 0 评论 -
485. Max Consecutive Ones
Given a binary array, find the maximum number of consecutive 1s in this array.Example 1:Input: [1,1,0,1,1,1]Output: 3Explanation: The first two digits or the last three digits are consecutiv原创 2017-07-14 09:43:13 · 187 阅读 · 0 评论 -
538. Convert BST to Greater Tree
Given a Binary Search Tree (BST), convert it to a Greater Tree such that every key of the original BST is changed to the original key plus sum of all keys greater than the original key in BST.Exam原创 2017-07-14 10:08:31 · 258 阅读 · 0 评论 -
476. Number Complement
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原创 2017-07-07 17:12:27 · 166 阅读 · 0 评论 -
520. Detect Capital+substring字符串截取
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-07-17 09:18:26 · 313 阅读 · 0 评论 -
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-07-17 10:20:27 · 175 阅读 · 0 评论 -
575. Distribute Candies
Given an integer array with even length, where different numbers in this array represent different kinds of candies. Each number means one candy of the corresponding kind. You need to distribute the原创 2017-07-12 19:59:43 · 233 阅读 · 0 评论 -
566. Reshape the Matrix重塑矩阵
In MATLAB, there is a very useful function called 'reshape', which can reshape a matrix into a new one with different size but keep its original data.You're given a matrix represented by a two-dim原创 2017-07-12 09:35:00 · 556 阅读 · 0 评论 -
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.T原创 2016-08-13 11:01:39 · 147 阅读 · 0 评论 -
374. Guess Number Higher or Lower
We are playing the Guess Game. The game is as follows:I pick a number from 1 to n. You have to guess which number I picked.Every time you guess wrong, I'll tell you whether the number is h原创 2016-08-14 10:41:17 · 156 阅读 · 0 评论 -
205. Isomorphic Strings
Given two strings s and t, determine if they are isomorphic.Two strings are isomorphic if the characters in s can be replaced to get t.All occurrences of a character must be replaced with anot原创 2016-08-14 11:19:07 · 155 阅读 · 0 评论 -
257. Binary Tree Paths
Given a binary tree, return all root-to-leaf paths.For example, given the following binary tree: 1 / \2 3 \ 5All root-to-leaf paths are:["1->2->5", "1->3"]/** *原创 2016-08-14 16:07:52 · 170 阅读 · 0 评论 -
225. Implement Stack using Queues
Implement the following operations of a stack using queues.push(x) -- Push element x onto stack.pop() -- Removes the element on top of the stack.top() -- Get the top element.empty() -- Return whet原创 2016-08-14 16:21:49 · 150 阅读 · 0 评论 -
223. Rectangle Area
Find the total area covered by two rectilinear rectangles in a 2D plane.Each rectangle is defined by its bottom left corner and top right corner as shown in the figure.Assume that the tota原创 2016-08-15 10:43:01 · 197 阅读 · 0 评论 -
19. Remove Nth Node From End of List
Given a linked list, remove the nth node from the end of list and return its head.For example, Given linked list: 1->2->3->4->5, and n = 2. After removing the second node from the end, the原创 2016-08-15 11:15:39 · 146 阅读 · 0 评论 -
637. Average of Levels in Binary Tree
Given a non-empty binary tree, return the average value of the nodes on each level in the form of an array.Example 1:Input: 3 / \ 9 20 / \ 15 7Output: [3, 14.5, 11]Explan原创 2017-07-10 18:37:05 · 2049 阅读 · 0 评论 -
500. Keyboard Row
Given 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 image below.Example 1:Input: ["Hello", "Alaska", "原创 2017-07-11 11:05:42 · 165 阅读 · 0 评论 -
557. Reverse Words in a String III
Given a string, you need to reverse the order of characters in each word within a sentence while still preserving whitespace and initial word order.Example 1:Input: "Let's take LeetCode contes原创 2017-07-11 14:29:48 · 218 阅读 · 0 评论 -
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-07-17 10:48:54 · 306 阅读 · 0 评论 -
606. Construct String from Binary Tree
You need to construct a string consists of parenthesis and integers from a binary tree with the preorder traversing way.The null node needs to be represented by empty parenthesis pair "()". And yo原创 2017-07-17 16:29:03 · 159 阅读 · 0 评论 -
506. Relative Ranks+数组赋值复制
Given scores of N athletes, find their relative ranks and the people with the top three highest scores, who will be awarded medals: "Gold Medal", "Silver Medal" and "Bronze Medal".Example 1:In原创 2017-07-19 14:35:07 · 271 阅读 · 0 评论 -
653. Two Sum IV - Input is a BST
Given a Binary Search Tree and a target number, return true if there exist two elements in the BST such that their sum is equal to the given target.Example 1:Input: 5 / \ 3 6 / \原创 2017-08-08 09:21:05 · 417 阅读 · 0 评论 -
409. Longest Palindrome+askii码总共128位
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-07-24 09:21:55 · 278 阅读 · 0 评论 -
628. Maximum Product of Three Numbers
Given an integer array, find three numbers whose product is maximum and output the maximum product.Example 1:Input: [1,2,3]Output: 6Example 2:Input: [1,2,3,4]Output: 24原创 2017-08-09 10:24:44 · 220 阅读 · 0 评论 -
447. Number of Boomerangs
Given n points in the plane that are all pairwise distinct, a "boomerang" is a tuple of points (i, j, k) such that the distance betweeni and j equals the distance between i and k (the order of t原创 2017-08-10 20:57:54 · 207 阅读 · 0 评论 -
504. Base 7
Given an integer, return its base 7 string representation.Example 1:Input: 100Output: "202"Example 2:Input: -7Output: "-10"Note: The input will be in range of [-1e7, 1e原创 2017-08-25 14:09:23 · 219 阅读 · 0 评论 -
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].Note:Each element in the result should appear as ma原创 2017-08-15 17:19:17 · 275 阅读 · 0 评论 -
268. Missing Number多种解法
Given an array containing n distinct numbers taken from 0, 1, 2, ..., n, find the one that is missing from the array.For example,Given nums = [0, 1, 3] return 2.解法一:直接,但是耗时比较多class Solut原创 2017-08-25 16:04:43 · 532 阅读 · 0 评论 -
551. Student Attendance Record I
You are given a string representing an attendance record for a student. The record only contains the following three characters:'A' : Absent.'L' : Late.'P' : Present.A student could be原创 2017-08-25 16:40:22 · 258 阅读 · 0 评论 -
771. Jewels and Stones
You're given strings J representing the types of stones that are jewels, and S representing the stones you have. Each character in Sis a type of stone you have. You want to know how many of the ston...原创 2018-02-11 15:12:21 · 245 阅读 · 0 评论 -
122. Best Time to Buy and Sell Stock II
Say you have an array for which the ith element is the price of a given stock on day i.Design an algorithm to find the maximum profit. You may complete as many transactions as you like (ie, buy on原创 2017-07-19 11:19:03 · 177 阅读 · 0 评论 -
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. Return 24原创 2017-07-19 10:38:59 · 229 阅读 · 0 评论 -
387. First Unique Character in a String字母表数组的运动
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:原创 2017-07-21 11:11:02 · 257 阅读 · 0 评论 -
598. Range Addition II
Given an m * n matrix M initialized with all 0's and several update operations.Operations are represented by a 2D array, and each operation is represented by an array with two positive integers a原创 2017-07-18 09:48:51 · 200 阅读 · 0 评论 -
599. Minimum Index Sum of Two Lists
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-07-18 10:56:24 · 212 阅读 · 0 评论
分享