
LeetCode
文章平均质量分 69
慕兰骆驼
爱Linux
展开
-
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(原创 2015-08-08 11:34:16 · 527 阅读 · 0 评论 -
258 - Add Digits
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原创 2015-09-15 05:41:14 · 540 阅读 · 0 评论 -
100 - SameTree
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. /** * Def原创 2015-09-15 05:56:25 · 576 阅读 · 0 评论 -
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原创 2015-09-13 14:26:08 · 379 阅读 · 0 评论 -
203 - Remove Linked List Elements
题目: Remove all elements from a linked list of integers that have value val. Example Given: 1 --> 2 --> 6 --> 3 --> 4 --> 5 --> 6, val = 6 Return: 1 --> 2 --> 3 --> 4 --> 5 Credits: Speci原创 2015-07-17 05:49:01 · 570 阅读 · 0 评论 -
233 - Number of Digit One
Number of Digit One Total Accepted: 307 Total Submissions: 1853 Given an integer n, count the total number of digit 1 appearing in all non-negative integers less than or equal to n.原创 2015-08-07 18:03:22 · 2340 阅读 · 0 评论 -
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? 没有达到上述的 O(1) space。 C++ 代码如下: Connecting to proxy server(10.109.247.19原创 2015-08-07 08:35:52 · 556 阅读 · 0 评论 -
238 - Product of Array Except Self
Given an array of n integers where n > 1, nums, return an array output such that output[i] is equal to the product of all the elements of nums except nums[i]. Solve it without division and in O原创 2015-08-06 08:14:58 · 445 阅读 · 0 评论 -
152 - Maximum Product Subarray 错误记录
Find the contiguous subarray within an array (containing at least one number) which has the largest product. For example, given the array [2,3,-2,4], the contiguous subarray [2,3] has the largest原创 2015-08-06 09:16:41 · 401 阅读 · 0 评论 -
241-Different Ways to Add Parentheses
Given a string of numbers and operators, return all possible results from computing all the different possible ways to group numbers and operators. The valid operators are+, - and *. Example 1 I原创 2015-08-05 07:20:51 · 2019 阅读 · 0 评论 -
8 - String to Integer (atoi)
Implement atoi to convert a string to an integer. Hint: Carefully consider all possible input cases. If you want a challenge, please do not see below and ask yourself what are the possible input ca原创 2015-08-31 12:00:37 · 957 阅读 · 0 评论 -
242-Valid Anagram
Given two strings s and t, write a function to determine if t is an anagram of s. For example, s = "anagram", t = "nagaram", return true. s = "rat", t = "car", return false. Note: You may a原创 2015-08-04 08:05:13 · 1249 阅读 · 0 评论 -
3 - Longest Substring Without Repeating Characters
Given a string, find the length of the longest substring without repeating characters. For example, the longest substring without repeating letters for "abcabcbb" is "abc", which the length is 3. Fo原创 2015-08-12 09:06:14 · 431 阅读 · 0 评论 -
2 - Add Two Numbers
You are given two linked lists representing two non-negative numbers. The digits are stored in reverse order and each of their nodes contain a single digit. Add the two numbers and return it as a link原创 2015-08-12 07:10:26 · 410 阅读 · 0 评论 -
1- Two Sum
Given an array of integers, find two numbers such that they add up to a specific target number. The function twoSum should return indices of the two numbers such that they add up to the target, whe原创 2015-08-11 20:55:57 · 450 阅读 · 0 评论 -
231 - power of two
Given an integer, write a function to determine if it is a power of two. Credits: Special thanks to @jianchao.li.fighter for adding this problem and creating all test cases. bool isPowerOfTwo(i原创 2015-08-11 08:27:26 · 457 阅读 · 0 评论 -
237 - Delete Node in a Linked List
题目: Write a function to delete a node (except the tail) in a singly linked list, given only access to that node. Supposed the linked list is 1 -> 2 -> 3 -> 4 and you are given the third node原创 2015-07-17 05:52:38 · 499 阅读 · 0 评论 -
21 - Merge Two Sorted Lists - LeetCode
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 lists. 分析: 就是归并排序的merge过程,只不过用链表实现了。 可以递归进行,也可以迭代。 自己的代码又臭又原创 2015-09-16 06:58:33 · 446 阅读 · 0 评论