- 博客(39)
- 问答 (1)
- 收藏
- 关注
原创 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
239
原创 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
267
原创 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
252
原创 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
192
原创 LeetCode 148. Sort List
描述 Sort a linked list in O(n log n) time using constant space complexity. 思路 排序算法有很多,对链表进行排序可以选择比较容易操作的算法,这里选择快速排序法,因为快速排序法比较容易用链表实现。快速排序法的思想:对未排序链表进行遍历,每次找出最小的元素位置,将最小的元素与未排序的第一个元素进行交换,继续遍历,知道所有的元...
2018-03-23 16:12:22
157
原创 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
141
原创 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
200
原创 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
178
原创 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
329
原创 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
223
原创 LeetCode 138. Copy List with Random Pointer
描述 A linked list is given such that each node contains an additional random pointer which could point to any node in the list or null. Return a deep copy of the list. 思路 由于有了一个随机的指针,因此这个单向链表有点像...
2018-03-17 22:25:12
139
原创 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
217
原创 LeetCode 134. Gas Station
描述 There are N gas stations along a circular route, where the amount of gas at station i is gas[i]. You have a car with an unlimited gas tank and it costs cost[i] of gas to travel from station i t...
2018-03-17 21:02:46
166
原创 LeetCode 133. Clone Graph
描述 Clone an undirected graph. Each node in the graph contains a label and a list of its neighbors. OJ’s undirected graph serialization: Nodes are labeled uniquely. We use # as a separator for ea...
2018-03-17 01:49:54
227
原创 LeetCode 131. Palindrome Partitioning
描述 Given a string s, partition s such that every substring of the partition is a palindrome. Return all possible palindrome partitioning of s. For example, given s = “aab”, Return [ ["aa","b"...
2018-03-17 00:50:19
442
原创 LeetCode 130. Surrounded Regions
描述 Given a 2D board containing ‘X’ and ‘O’ (the letter O), capture all regions surrounded by ‘X’. A region is captured by flipping all ‘O’s into ‘X’s in that surrounded region. For example, X ...
2018-03-15 20:38:17
217
原创 LeetCode 129. Sum Root to Leaf Numbers
描述 Given a binary tree containing digits from 0-9 only, each root-to-leaf path could represent a number. An example is the root-to-leaf path 1->2->3 which represents the number 123. Find the...
2018-03-15 15:59:32
138
原创 LeetCode 127. Word Ladder
描述 Given two words (beginWord and endWord), and a dictionary’s word list, find the length of shortest transformation sequence from beginWord to endWord, such that: Only one letter can be changed a...
2018-03-15 15:38:32
178
原创 LeetCode 120. Triangle
描述 Given a triangle, find the minimum path sum from top to bottom. Each step you may move to adjacent numbers on the row below. For example, given the following triangle [ [2], [3,4], ...
2018-03-14 16:23:28
135
原创 LeetCode 114. Flatten Binary Tree to Linked List
描述 Given a binary tree, flatten it to a linked list in-place. For example, Given 1 / \ 2 5 / \ \ 3 4 6 The flattened tree should look like: 1...
2018-03-13 18:45:33
134
原创 LeetCode 113. Path Sum II
描述 Given a binary tree and a sum, find all root-to-leaf paths where each path’s sum equals the given sum. For example: Given the below binary tree and sum = 22, 5 / \ ...
2018-03-13 17:46:36
166
原创 LeetCode 109. Convert Sorted List to Binary Search Tree
描述 Given a singly linked list where elements are sorted in ascending order, convert it to a height balanced BST. For this problem, a height-balanced binary tree is defined as a binary tree in which...
2018-03-13 17:09:22
141
原创 LeetCode 106. Construct Binary Tree from Inorder and Postorder Traversal
描述 Given inorder and postorder traversal of a tree, construct the binary tree. Note: You may assume that duplicates do not exist in the tree. For example, given inorder = [9,3,15,20,7] postorde...
2018-03-13 16:30:36
156
原创 LeetCode 105. Construct Binary Tree from Preorder and Inorder Traversal
描述 Given preorder and inorder traversal of a tree, construct the binary tree. Note: You may assume that duplicates do not exist in the tree. For example, given preorder = [3,9,20,15,7] inorder ...
2018-03-13 16:26:00
168
原创 LeetCode 103. Binary Tree Zigzag Level Order Traversal
描述 Given a binary tree, return the zigzag level order traversal of its nodes’ values. (ie, from left to right, then right to left for the next level and alternate between). For example: Given bina...
2018-03-12 21:35:16
128
原创 LeetCode 102. Binary Tree Level Order Traversal
描述 Given a binary tree, return the level order traversal of its nodes’ values. (ie, from left to right, level by level). For example: Given binary tree [3,9,20,null,null,15,7], 3 / \ ...
2018-03-10 18:17:02
152
原创 LeetCode 98. Validate Binary Search Tree
描述 Given a binary tree, determine if it is a valid binary search tree (BST). Assume a BST is defined as follows: The left subtree of a node contains only nodes with keys less than the node’s key. ...
2018-03-10 17:44:48
195
原创 96. Unique Binary Search Trees
描述 Given n, how many structurally unique BST’s (binary search trees) that store values 1…n? For example, Given n = 3, there are a total of 5 unique BST’s. 1 3 3 2 1 ...
2018-03-09 15:53:22
118
原创 LeetCode 95. Unique Binary Search Trees II
描述 Given an integer n, generate all structurally unique BST’s (binary search trees) that store values 1…n. For example, Given n = 3, your program should return all 5 unique BST’s shown below. ...
2018-03-09 15:20:08
142
原创 94. Binary Tree Inorder Traversal
描述 Given a binary tree, return the inorder traversal of its nodes’ values. For example: Given binary tree [1,null,2,3], 1 \ 2 / 3 return [1,3,2]. Note: Recursive solution ...
2018-03-07 15:15:24
125
原创 93. Restore IP Addresses
描述 Given a string containing only digits, restore it by returning all possible valid IP address combinations. For example: Given “25525511135”, return [“255.255.11.135”, “255.255.111.35”]. (Orde...
2018-03-07 15:00:22
137
原创 LeetCode 92. Reverse Linked List II
描述 Reverse a linked list from position m to n. Do it in-place and in one-pass. For example: Given 1->2->3->4->5->NULL, m = 2 and n = 4, return 1->4->3->2->5->NULL. ...
2018-03-06 16:42:01
140
原创 LeetCode 91. Decode Ways
描述 A message containing letters from A-Z is being encoded to numbers using the following mapping: 'A' -> 1 'B' -> 2 ... 'Z' -> 26 Given an encoded message containing digits, determine ...
2018-03-05 17:36:54
270
原创 LeetCode 90. Subsets II
LeetCode 90. Subsets II 解题的一种思路 描述 Given a collection of integers that might contain duplicates, nums, return all possible subsets (the power set). Note: The solution set must not contain duplicat...
2018-03-05 16:49:54
186
原创 LeetCode 78. Subsets 解题思路
描述 Given a set of distinct integers, nums, return all possible subsets (the power set). Note: The solution set must not contain duplicate subsets. For example, If nums = [1,2,3], a solution is: ...
2018-03-05 16:47:28
283
1
原创 lintcode-31数组划分
描述 给出一个整数数组 nums 和一个整数 k。划分数组(即移动数组 nums 中的元素),使得: 1、所有小于k的元素移到左边 2、所有大于等于k的元素移到右边 返回数组划分的位置,即数组中第一个位置 i,满足 nums[i] 大于等于 k。 样例 给出数组 nums = [3,2,2,1] 和 k = 2,返回 1. 思路 比k小的在左边,比k大的在右边,并不需要严
2018-01-04 21:05:33
339
原创 lintcode-29交叉字符串
描述 给出三个字符串:s1、s2、s3,判断s3是否由s1和s2交叉构成。 样例 比如 s1 = “aabcc” s2 = “dbbca” 当 s3 = “aadbbcbcac”,返回 true. 当 s3 = “aadbbbaccc”, 返回 false. 思路 如果s3是由s1、s2交叉构成,那么一定满足一下条件 1、s3的长度等于s1的长度加s2的长度。 2、s3
2018-01-03 22:10:36
405
原创 lintcode-5丑数
描述: 设计一个算法,找出只含素因子2,3,5 的第 n 小的数。符合条件的数如:1, 2, 3, 4, 5, 6, 8, 9, 10, 12… 样例: 如果n = 9, 返回 10 思路 1.一个数只含因子2、3、5,说明这个数不断的整除2、3、5最后能得到1,一个数是丑数可以用以下的伪代码表示 while(num%5==0){ num=num/5; } while(num%3==0){
2018-01-02 23:37:59
212
原创 lintcode题目-3.统计数字
统计数字 描述:计算数字k在0到n中的出现的次数,k可能是0~9的一个值 样例:例如n=12,k=1,在 [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12],我们发现1出现了5次 (1, 10, 11, 12) 解题思路1:先将大问题分解成小问题,题目中需要统计0-n中出现的次数,可以判断一个数中出现了几次k,在累计即可得到共出现的次数。 问题就变成了,给定一个数
2018-01-02 22:44:28
458
空空如也
携程2018秋招笔试编程题
2017-09-21
TA创建的收藏夹 TA关注的收藏夹
TA关注的人
RSS订阅