LeetCode
炼丹大法
这个作者很懒,什么都没留下…
展开
-
LeetCode 502.IPO
题目描述假设 LeetCode 即将开始其 IPO。为了以更高的价格将股票卖给风险投资公司,LeetCode希望在 IPO 之前开 展一些项目以增加其资本。 由于资源有限,它只能在 IPO 之前完成最多 k 个不同的项目。帮助 LeetCode 设计完成最多 k 个不同项目后得到最大总资本的方式。给定若干个项目。对于每个项目 i,它都有一个纯利润 Pi,并且需要最小的资本 Ci 来启动相应...原创 2019-02-27 21:09:22 · 190 阅读 · 0 评论 -
LeetCode 150. Evaluate Reverse Polish Notation
题目描述Evaluate the value of an arithmetic expression in Reverse Polish Notation.Valid operators are +, -, *, /. Each operand may be an integer or another expression.Note:Division between two integ...原创 2019-03-02 16:38:55 · 93 阅读 · 0 评论 -
LeetCode 641. Design Circular Deque
题目描述Design your implementation of the circular double-ended queue (deque).Your implementation should support following operations:MyCircularDeque(k): Constructor, set the size of the deque to be ...原创 2019-03-02 18:02:03 · 112 阅读 · 0 评论 -
LeetCode 239. Sliding Window Maximum
题目描述Given an array nums, there is a sliding window of size k which is moving from the very left of the array to the very right. You can only see the k numbers in the window. Each time the sliding wi...原创 2019-03-02 18:10:04 · 107 阅读 · 0 评论 -
LeetCode 69. Sqrt(x)
题目描述Implement int sqrt(int x).Compute and return the square root of x, where x is guaranteed to be a non-negative integer.Since the return type is an integer, the decimal digits are truncated and...原创 2019-03-05 21:18:25 · 80 阅读 · 0 评论 -
LeetCode 390. Elimination Game
题目描述There is a list of sorted integers from 1 to n. Starting from left to right, remove the first number and every other number afterward until you reach the end of the list.Repeat the previous st...原创 2019-03-08 22:58:45 · 487 阅读 · 0 评论 -
LeetCode 202. Happy Number
题目描述Write an algorithm to determine if a number is “happy”.A happy number is a number defined by the following process: Starting with any positive integer, replace the number by the sum of the squ...原创 2019-03-10 16:11:48 · 79 阅读 · 0 评论 -
LeetCode 617.Merge Two Binary Trees
题目描述:Given two binary trees and imagine that when you put one of them to cover the other, some nodes of the two trees are overlapped while the others are not.You need to merge them into a new bina...原创 2019-03-07 22:40:20 · 61 阅读 · 0 评论 -
LeetCode 8. String to Integer (atoi)
题目描述:Implement atoi which converts a string to an integer.The function first discards as many whitespace characters as necessary until the first non-whitespace character is found. Then, starting fr...原创 2019-03-07 23:27:20 · 102 阅读 · 0 评论 -
LeetCode 151. Reverse Words in a String
题目描述:Given an input string, reverse the string word by word.Example 1:Input: "the sky is blue"Output: "blue is sky the"Example 2:Input: " hello world! "Output: "world! hello"Explanation: ...原创 2019-03-07 23:48:55 · 112 阅读 · 0 评论 -
LeetCode 414. Third Maximum Number
题目描述Given a non-empty array of integers, return the third maximum number in this array. If it does not exist, return the maximum number. The time complexity must be in O(n).Example 1:Input: [3, 2...原创 2019-03-02 15:25:09 · 78 阅读 · 0 评论 -
LeetCode 20. Valid Parentheses
题目描述Given a string containing just the characters ‘(’, ‘)’, ‘{’, ‘}’, ‘[’ and ‘]’, determine if the input string is valid.An input string is valid if:Open brackets must be closed by the same type...原创 2019-03-02 14:15:36 · 73 阅读 · 0 评论 -
LeetCode 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, and you may not use the...原创 2019-02-27 22:30:04 · 102 阅读 · 0 评论 -
LeetCode 15.Three Sum
题目描述Given an array nums of n integers, are there elements a, b, c in nums such that a + b + c = 0? Find all unique triplets in the array which gives the sum of zero.Note:The solution set must not...原创 2019-02-27 23:42:41 · 127 阅读 · 0 评论 -
LeetCode 233.Number of Digit One
题目描述Given an integer n, count the total number of digit 1 appearing in all non-negative integers less than or equal to n.Example:Input: 13Output: 6Explanation: Digit 1 occurred in the following n...原创 2019-02-23 19:50:03 · 100 阅读 · 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 eleme...原创 2019-02-28 20:58:41 · 104 阅读 · 0 评论 -
数组
1.实现一个支持动态扩容的数组基本思路:当元素数量等于数组大小时,如果继续添加元素,则将数组容量扩大为原来的两倍;如果元素个数达到数组容量的1/4时,将数组容量收缩为原来的1/2。public class ResizingArray<Integer>{ private int[] a = new int[]; private N = 0; private void res...原创 2019-02-28 20:59:45 · 101 阅读 · 0 评论 -
LeetCode 141. Linked List Cycle
题目描述:Given a linked list, determine if it has a cycle in it.To represent a cycle in the given linked list, we use an integer pos which represents the position (0-indexed) in the linked list where ...原创 2019-02-28 21:38:18 · 87 阅读 · 0 评论 -
LeetCode 23. Merge k Sorted Lists
题目描述:Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity.Example:Input:[1-&amp;gt;4-&amp;gt;5,1-&amp;gt;3-&amp;gt;4,2-&amp;gt;6]Output: 1-&amp;g原创 2019-02-28 21:44:44 · 71 阅读 · 0 评论 -
链表
1.实现单链表、循环链表、双向链表,支持增删操作2.实现单链表反转public class reverseList{ public class ListNode { int val; ListNode next; ListNode(int x) { val = x; } } public ListNode reverse(ListNode node) { List...原创 2019-02-28 21:48:03 · 92 阅读 · 0 评论 -
LeetCode 737.My Calendar III
题目描述Implement a MyCalendarThree class to store your events. A new event can always be added.Your class will have one method, book(int start, int end). Formally, this represents a booking on the ha...原创 2019-02-25 21:24:26 · 330 阅读 · 0 评论 -
LeetCode 344. Reverse String
题目描述Write a function that reverses a string. The input string is given as an array of characters char[].Do not allocate extra space for another array, you must do this by modifying the input array ...原创 2019-03-07 23:54:26 · 107 阅读 · 0 评论