
LeetCode
qufayudao
这个作者很懒,什么都没留下…
展开
-
LeetCode 137. Single Number II
描述 Given an array of integers, every element appears three times except for one, which appears exactly once. Find that single one. Note: Your algorithm should have a linear runtime complexity. Co...原创 2018-03-17 21:53:24 · 183 阅读 · 0 评论 -
LeetCode 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 larg...原创 2018-03-25 16:49:02 · 235 阅读 · 0 评论 -
LeetCode 151. Reverse Words in a String
描述 Given an input string, reverse the string word by word. For example, Given s = “the sky is blue”, return “blue is sky the”. Update (2015-02-12): For C programmers: Try to solve it in-place ...原创 2018-03-24 18:37:27 · 228 阅读 · 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. Some examples: ["2", "1", "+...原创 2018-03-23 18:17:16 · 173 阅读 · 0 评论 -
LeetCode 148. Sort List
描述 Sort a linked list in O(n log n) time using constant space complexity. 思路 排序算法有很多,对链表进行排序可以选择比较容易操作的算法,这里选择快速排序法,因为快速排序法比较容易用链表实现。快速排序法的思想:对未排序链表进行遍历,每次找出最小的元素位置,将最小的元素与未排序的第一个元素进行交换,继续遍历,知道所有的元...原创 2018-03-23 16:12:22 · 137 阅读 · 0 评论 -
LeetCode 147. Insertion Sort List
描述 Sort a linked list using insertion sort. 思路 首先要明白直接插入排序的概念:遍历一个数组,当找到一个数a,该数比前一个数更小,则将a之前的所有大于a的数全部向前移动1,将a插入最后一个大于该数的位置。用数组排序的代码如下 代码(c#) public void InsertSort(int[] arr) { ...原创 2018-03-22 23:56:56 · 124 阅读 · 0 评论 -
LeetCode 143. Reorder List
描述 Given a singly linked list L: L0→L1→…→Ln-1→Ln, reorder it to: L0→Ln→L1→Ln-1→L2→Ln-2→… You must do this in-place without altering the nodes’ values. For example, Given {1,2,3,4}, reorder it t...原创 2018-03-22 15:11:25 · 154 阅读 · 0 评论 -
LeetCode 144. Binary Tree Preorder Traversal
描述 Given a binary tree, return the preorder traversal of its nodes’ values. For example: Given binary tree [1,null,2,3], 1 \ 2 / 3 return [1,2,3]. Note: Recursive solution i...原创 2018-03-22 22:13:13 · 179 阅读 · 0 评论 -
LeetCode 142. Linked List Cycle II
描述 Given a linked list, return the node where the cycle begins. If there is no cycle, return null. Note: Do not modify the linked list. Follow up: Can you solve it without using extra space? 思...原创 2018-03-18 15:50:50 · 292 阅读 · 0 评论 -
139. Word Break
描述 Given a non-empty string s and a dictionary wordDict containing a list of non-empty words, determine if s can be segmented into a space-separated sequence of one or more dictionary words. You may...原创 2018-03-18 14:38:30 · 200 阅读 · 0 评论 -
LeetCode 153. Find Minimum in Rotated Sorted Array
描述 Suppose an array sorted in ascending order is rotated at some pivot unknown to you beforehand. (i.e., 0 1 2 4 5 6 7 might become 4 5 6 7 0 1 2). Find the minimum element. You may assume no du...原创 2018-03-25 17:59:56 · 202 阅读 · 0 评论