![](https://img-blog.csdnimg.cn/20201014180756923.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
LeetCode--Easy
文章平均质量分 52
sophia_tone2w
这个作者很懒,什么都没留下…
展开
-
LeetCode--No.771-Jewels and Stones
虽然是很简单的题,但是发现一个问题。就是如何遍历一个String更好一点class Solution { public int numJewelsInStones(String J, String S) { if (J == null || S == null) return 0; Set<Character> set = n...原创 2019-05-13 07:02:28 · 86 阅读 · 0 评论 -
LeetCode--No.1--Two Sum
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 =原创 2016-09-05 03:12:20 · 236 阅读 · 0 评论 -
LeetNode--No.7--Reverse Integer
Reverse digits of an integer.Example1: x = 123, return 321Example2: x = -123, return -321一开始呢,我的思路是很好的。于是我写下了这些代码public class Solution { public int reverse(int x) { int symbol原创 2016-09-09 11:42:22 · 343 阅读 · 0 评论 -
LeetCode--No.203--Remove Linked List Elements
Remove all elements from a linked list of integers that have value val.ExampleGiven: 1 --> 2 --> 6 --> 3 --> 4 --> 5 --> 6, val = 6Return: 1 --> 2 --> 3 --> 4 --> 5Credits:Special thanks原创 2016-08-19 03:47:39 · 167 阅读 · 0 评论 -
LeetCode--No.234--Palindrome Linked List
Given a singly linked list, determine if it is a palindrome.Follow up:Could you do it in O(n) time and O(1) space?Subscribe to see which companies asked this question空间复杂度O(n)的思路很容原创 2016-08-18 09:10:13 · 187 阅读 · 0 评论 -
LeetCode--No.219--Contains Duplicate II--有个地方不太懂
Given an array of integers and an integer k, find out whether there are two distinct indices i and j in the array such that nums[i] = nums[j] and the difference between i and j is at most k.原创 2016-08-18 03:43:05 · 207 阅读 · 0 评论 -
LeetCode--No.88--Merge Sorted Array
Given two sorted integer arrays nums1 and nums2, merge nums2 into nums1 as one sorted array.Note:You may assume that nums1 has enough space (size that is greater or equal to m + n) to hold addit原创 2016-08-18 02:31:26 · 168 阅读 · 0 评论 -
LeetCode--No.290--Word Pattern
Given a pattern and a string str, find if str follows the same pattern.Here follow means a full match, such that there is a bijection between a letter in pattern and a non-emptyword in str.原创 2016-08-18 01:41:32 · 236 阅读 · 0 评论 -
LeetCode--No.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-18 01:18:56 · 170 阅读 · 0 评论 -
LeetCode--No.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-17 11:57:41 · 192 阅读 · 0 评论 -
LeetCode--No.235--Lowest Common Ancestor of a Binary Search Tree
235. Lowest Common Ancestor of a Binary Search Tree QuestionEditorial Solution My SubmissionsTotal Accepted: 80240Total Submissions: 214043Difficulty: EasyGiven a b原创 2016-07-22 03:25:21 · 245 阅读 · 0 评论 -
LeetCode--No.110--Balanced Binary Tree--待完善
Given a binary tree, determine if it is height-balanced.For this problem, a height-balanced binary tree is defined as a binary tree in which the depth of the two subtrees of every node never diffe原创 2016-07-22 03:18:47 · 270 阅读 · 0 评论 -
LeetCode--No.107--Binary Tree Level Order Traversal II
Given a binary tree, return the bottom-up level order traversal of its nodes' values. (ie, from left to right, level by level from leaf to root).For example:Given binary tree [3,9,20,null,null,1原创 2016-07-22 02:23:08 · 155 阅读 · 0 评论 -
LeetCode--No.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-17 04:41:03 · 175 阅读 · 0 评论 -
LeetCode--No.67--Add Binary
Given two binary strings, return their sum (also a binary string).For example,a = "11"b = "1"Return "100".Subscribe to see which companies asked this question注意StringBuilder的用法。app原创 2016-09-05 04:35:14 · 250 阅读 · 0 评论 -
LeetCode--No.28--Implement strStr()
Implement strStr().Returns the index of the first occurrence of needle in haystack, or -1 if needle is not part of haystack.Subscribe to see which companies asked this question真的需要更多的考虑一原创 2016-09-05 05:04:49 · 181 阅读 · 0 评论 -
LeetCode--No.9--Palindrome Number
Determine whether an integer is a palindrome. Do this without extra space.click to show spoilers.Palindrome Number的意思就是:对称的数字。负数不算。public class Solution { public boolean isPalind原创 2016-08-15 04:03:14 · 198 阅读 · 0 评论 -
LeetCode--No.119--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].Note:Could you optimize your algorithm to use only O(k) extra space?思路:延续之前的思路。毕原创 2016-08-15 01:26:50 · 291 阅读 · 0 评论 -
LeetCode--No.172--Factorial Trailing Zeroes
Given an integer n, return the number of trailing zeroes in n!.Note: Your solution should be in logarithmic time complexity.Credits:Special thanks to @ts for adding this problem and creating原创 2016-08-15 00:43:49 · 153 阅读 · 0 评论 -
LeetCode--No.26--Remove Duplicates from Sorted Array
Given a sorted array, remove the duplicates in place such that each element appear only once and return the new length.Do not allocate extra space for another array, you must do this in place with原创 2016-08-15 00:15:35 · 213 阅读 · 0 评论 -
LeetCode--No.232--Implement Queue using Stacks
Implement the following operations of a queue using stacks.push(x) -- Push element x to the back of queue.pop() -- Removes the element from in front of queue.peek() -- Get the front element.empty(原创 2016-08-14 23:40:30 · 169 阅读 · 0 评论 -
LeetCode--No.204--Count Primes
Description:Count the number of prime numbers less than a non-negative number, n.Credits:Special thanks to @mithmatt for adding this problem and creating all test cases.不敢说是自己的思路。我发现我刷原创 2016-09-06 03:53:47 · 203 阅读 · 0 评论 -
LeetCode--No.14--Longest Common Prefix
Write a function to find the longest common prefix string amongst an array of strings.Subscribe to see which companies asked this question哎。。不认识prefix。。。脑残啊public class Solution { publ原创 2016-08-25 22:40:46 · 223 阅读 · 0 评论 -
LeetCode--No.190--Reverse Bits
Reverse bits of a given 32 bits unsigned integer.For example, given input 43261596 (represented in binary as 00000010100101000001111010011100), return 964176192 (represented in binary as 001110010原创 2016-08-25 22:24:03 · 314 阅读 · 0 评论 -
LeetCode--No.118--Pascal's Triangle
Given numRows, generate the first numRows of Pascal's triangle.For example, given numRows = 5,Return[ [1], [1,1], [1,2,1], [1,3,3,1], [1,4,6,4,1]]Subscribe to see原创 2016-08-14 03:47:48 · 171 阅读 · 0 评论 -
LeetCode--No.66--Plus One
Given a non-negative number represented as an array of digits, plus one to the number.The digits are stored such that the most significant digit is at the head of the list.Subscribe to see原创 2016-08-14 03:04:05 · 234 阅读 · 0 评论 -
LeetCode--No.198--House Robber
You are a professional robber planning to rob houses along a street. Each house has a certain amount of money stashed, the only constraint stopping you from robbing each of them is that adjacent house原创 2016-08-14 02:46:45 · 295 阅读 · 0 评论 -
LeetCode--No.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-14 01:57:21 · 487 阅读 · 0 评论 -
LeetCode--No.303--Range Sum Query - Immutable
Given an integer array nums, find the sum of the elements between indices i and j (i ≤ j), inclusive.Example:Given nums = [-2, 0, 3, -5, 2, -1]sumRange(0, 2) -> 1sumRange(2, 5) -> -1sumRange原创 2016-09-05 05:18:24 · 188 阅读 · 0 评论 -
LeetCode--No.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-17 04:07:46 · 287 阅读 · 0 评论 -
LeetCode--No.299--Bulls and Cows
You are playing the following Bulls and Cows game with your friend: You write down a number and ask your friend to guess what the number is. Each time your friend makes a guess, you provide a hint t原创 2016-08-17 03:36:06 · 195 阅读 · 0 评论 -
LeetCode--No.226--Invert Binary Tree
Invert a binary tree. 4 / \ 2 7 / \ / \1 3 6 9to 4 / \ 7 2 / \ / \9 6 3 1递归:为啥我的代码总这么丑/** * Definition for a binary tree node. * public class原创 2016-07-16 04:23:10 · 170 阅读 · 0 评论 -
LeetCode--No.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.Subscribe to see which compani原创 2016-07-16 04:05:55 · 171 阅读 · 0 评论 -
LeetCode--No.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.Subscr原创 2016-07-16 04:01:03 · 220 阅读 · 0 评论 -
LeetNode--No.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-07-16 03:55:01 · 198 阅读 · 0 评论 -
LeetCode--No.58--Length of Last Word
Given a string s consists of upper/lower-case alphabets and empty space characters ' ', return the length of last word in the string.If the last word does not exist, return 0.Note: A word is原创 2016-07-14 06:31:52 · 183 阅读 · 0 评论 -
LeetCode--No.38--Count and Say
The count-and-say sequence is the sequence of integers beginning as follows:1, 11, 21, 1211, 111221, ...1 is read off as "one 1" or 11.11 is read off as "two 1s" or 21.21 is read off as原创 2016-07-14 05:58:34 · 189 阅读 · 0 评论 -
LeetCode--No.20--Valid Parentheses
Given a string containing just the characters '(', ')', '{', '}', '[' and ']', determine if the input string is valid.The brackets must close in the correct order, "()" and "()[]{}" are all原创 2016-07-14 04:43:36 · 167 阅读 · 0 评论 -
LeetCode--No.345--Reverse Vowels of a String
Write a function that takes a string as input and reverse only the vowels of a string.Example 1:Given s = "hello", return "holle".Example 2:Given s = "leetcode", return "leotcede".原创 2016-07-13 23:57:58 · 199 阅读 · 0 评论 -
LeetCode--No.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 include 2, 3, 5. For example, 6, 8 are ugly while 14 is not ugly sinc原创 2016-06-15 03:14:54 · 191 阅读 · 0 评论