刷题
文章平均质量分 66
Krysta1
还是个学生
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
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.Note:A leaf is a node with no ...原创 2019-03-28 10:13:01 · 218 阅读 · 0 评论 -
56. Merge Intervals
题目描述:Given a collection of intervals, merge all overlapping intervals.For example,Given [1,3],[2,6],[8,10],[15,18],return [1,6],[8,10],[15,18].我的思路: 给出一个类型为intervals的列表,intervals就是一个区间,有start和e...原创 2018-03-14 10:32:06 · 171 阅读 · 0 评论 -
74. Search a 2D Matrix
题目描述:Write an efficient algorithm that searches for a value in an m x n matrix. This matrix has the following properties:Integers in each row are sorted from left to right.The first integer of each ro...原创 2018-03-20 12:00:57 · 251 阅读 · 0 评论 -
73. Set Matrix Zeroes
题目描述:Given a m x n matrix, if an element is 0, set its entire row and column to 0. Do it in place.click to show follow up.Follow up:Did you use extra space?A straight forward solution using O(mn) spac...原创 2018-03-20 11:41:21 · 174 阅读 · 0 评论 -
71. Simplify Path
题目描述:Given an absolute path for a file (Unix-style), simplify it.For example,path = "/home/", => "/home"path = "/a/./b/../../c/", => "/c"click to show corner cases.Corner Cases:Did you consider ...原创 2018-03-20 10:18:32 · 190 阅读 · 0 评论 -
55. Jump Game
题目描述:Given an array of non-negative integers, you are initially positioned at the first index of the array.Each element in the array represents your maximum jump length at that position.Determine if y...原创 2018-03-14 08:55:22 · 249 阅读 · 0 评论 -
82. Remove Duplicates from Sorted List II
题目描述:Given a sorted linked list, delete all nodes that have duplicate numbers, leaving only distinct numbers from the original list.For example,Given 1->2->3->3->4->4->5, return 1-&g...原创 2018-03-23 11:19:44 · 200 阅读 · 0 评论 -
83. Remove Duplicates from Sorted List
题目描述:Given a sorted linked list, delete all duplicates such that each element appear only once.For example,Given 1->1->2, return 1->2.Given 1->1->2->3->3, return 1->2->3.我得思...原创 2018-03-23 10:11:28 · 184 阅读 · 0 评论 -
81. Search in Rotated Sorted Array II
题目描述: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).Write a function to determine if a given target is i...原创 2018-03-22 19:54:43 · 197 阅读 · 0 评论 -
54. Spiral Matrix
题目描述:Given a matrix of m x n elements (m rows, n columns), return all elements of the matrix in spiral order.For example,Given the following matrix:[ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ]]You sho...原创 2018-03-13 11:06:17 · 210 阅读 · 0 评论 -
53. Maximum Subarray
题目描述:Find the contiguous subarray within an array (containing at least one number) which has the largest sum.For example, given the array [-2,1,-3,4,-1,2,1,-5,4],the contiguous subarray [4,-1,2,1] has...原创 2018-03-13 08:42:48 · 211 阅读 · 0 评论 -
70. Climbing Stairs
题目描述:You are climbing a stair case. It takes n steps to reach to the top.Each time you can either climb 1 or 2 steps. In how many distinct ways can you climb to the top?Note: Given n will be a positiv...原创 2018-03-19 10:41:34 · 229 阅读 · 0 评论 -
69. Sqrt(x)
题目描述:Implement int sqrt(int x).Compute and return the square root of x.x is guaranteed to be a non-negative integer.我的思路: 就是求一个非负数的开方,要求向下取整。 就是在1~x范围中搜索呗,先试了下直接查找1~x/2,超时了。既然是个有序序列就使用二分...原创 2018-03-19 10:32:42 · 184 阅读 · 0 评论 -
67. Add Binary
题目描述:Given two binary strings, return their sum (also a binary string).For example,a = "11"b = "1"Return "100".我的思路: 给定连个二进制数,用字符串表示,计算他们的加和,然后也以字符串的形式返回。 先把两个字符串翻转,从低位加到高位,同时用一个p保存进位,如果...原创 2018-03-19 09:53:27 · 185 阅读 · 0 评论 -
80. Remove Duplicates from Sorted Array II
题目描述:Follow up for "Remove Duplicates":What if duplicates are allowed at most twice?For example,Given sorted array nums = [1,1,1,2,2,3],Your function should return length = 5, with the first five elem...原创 2018-03-22 13:05:08 · 319 阅读 · 0 评论 -
50. Pow(x, n)
题目描述:Implement pow(x, n).Example 1:Input: 2.00000, 10Output: 1024.00000Example 2:Input: 2.10000, 3Output: 9.26100我的思路: 题目说明很简单,就是自己实现乘方运算。先试试循环但是估计不行哈。 试了两次水,大致问题是n的类型是int,所以有可能是负数和零,...原创 2018-03-12 12:05:29 · 223 阅读 · 0 评论 -
49. Group Anagrams
题目描述:Given an array of strings, group anagrams together.For example, given: ["eat", "tea", "tan", "ate", "nat", "bat"], Return:[ ["ate", "eat","tea"], ["nat&原创 2018-03-12 11:20:55 · 161 阅读 · 0 评论 -
48. Rotate Image
题目描述:You are given an n x n 2D matrix representing an image.Rotate the image by 90 degrees (clockwise).Note:You have to rotate the image in-place, which means you have to modify the input 2D matrix di...原创 2018-03-12 10:25:29 · 143 阅读 · 0 评论 -
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 defi...原创 2018-03-14 11:43:12 · 196 阅读 · 0 评论 -
59. Spiral Matrix II
题目描述:Given an integer n, generate a square matrix filled with elements from 1 to n2 in spiral order.For example,Given n = 3,You should return the following matrix:[ [ 1, 2, 3 ], [ 8, 9, 4 ], [ 7, 6...原创 2018-03-14 12:10:33 · 198 阅读 · 0 评论 -
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 / \ 9...原创 2019-01-23 04:31:07 · 215 阅读 · 0 评论 -
101. Symmetric Tree
题目描述:Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center).For example, this binary tree [1,2,2,3,4,4,3] is symmetric: 1 / \ 2 2 / \ / \3 4 ...原创 2019-01-23 03:46:36 · 243 阅读 · 0 评论 -
100. Same Tree
题目描述:给定两个二叉树,写一个函数来检查它们是否相同。如果两棵树在结构上相同并且节点具有相同的值,则认为它们是相同的。示例 1:输入 : 1 1 / \ / \ 2 3 2 3 [1,2,3], [1,2,3]输出: true示例 2:输入 : 1 1...原创 2018-03-28 11:34:33 · 266 阅读 · 0 评论 -
98. Validate Binary Search Tree
题目描述:给定一个二叉树,判断其是否是一个有效的二叉搜索树。一个二叉搜索树有如下定义:左子树只包含小于当前节点的数。右子树只包含大于当前节点的数。所有子树自身必须也是二叉搜索树。示例 1: 2 / \ 1 3二叉树[2,1,3], 返回 true.示例 2: 1 / \ 2 3二叉树 [1,2,3], 返回 false.我的思路: 中序遍历...原创 2018-03-28 10:58:04 · 228 阅读 · 0 评论 -
95. Unique Binary Search Trees II
题目描述:给定一个整数 n,生成所有由 1...n 为节点组成的不同的二叉查找树。例如,给定 n = 3,则返回所有 5 种不同形态的二叉查找树: 1 3 3 2 1 \ / / / \ \ 3 2 1 1 3 2 / / \...原创 2018-03-28 10:44:16 · 266 阅读 · 0 评论 -
94. Binary Tree Inorder Traversal
题目描述:给定一个二叉树,返回其中序遍历。例如:给定二叉树 [1,null,2,3], 1 \ 2 / 3返回 [1,3,2].说明: 递归算法很简单,你可以通过迭代算法完成吗?我的思路: 就是非递归遍历二叉树,用栈来实现。基本原则是,如果有左孩子进栈,知道没有左孩子。如果栈不空,弹出栈顶元素,同时去遍历根节点的右子树。在节点不空或者栈不空的情况...原创 2018-03-28 09:50:01 · 223 阅读 · 0 评论 -
96. Unique Binary Search Trees
题目描述:给出 n,问由 1...n 为节点组成的不同的二叉查找树有多少种?例如,给出 n = 3,则有 5 种不同形态的二叉查找树: 1 3 3 2 1 \ / / / \ \ 3 2 1 1 3 2 / / \ ...原创 2018-03-28 10:14:00 · 223 阅读 · 0 评论 -
93. Restore IP Addresses(DFS)
题目描述:给定一个只包含数字的字符串,复原它并返回所有可能的IP地址格式。例如:给定 "25525511135",返回 ["255.255.11.135", "255.255.111.35"]. (我们可以不考虑数组内元素的顺序)我的思路:我的代码:Discuss:class Solution: def restoreIpAddresses(self, s): """ ...原创 2018-03-27 19:44:23 · 432 阅读 · 0 评论 -
92. Reverse Linked List II
题目描述:反转从位置 m 到 n 的链表。用一次遍历在原地完成反转。例如:给定 1->2->3->4->5->NULL, m = 2 和 n = 4,返回 1->4->3->2->5->NULL.注意:给定 m,n 满足以下条件:1 ≤ m ≤ n ≤ 列表长度。我的思路: 先设定一个dummy节点标示整个链表,用pre来表...原创 2018-03-27 19:18:19 · 222 阅读 · 0 评论 -
91. Decode Ways
中文版leetcode上线啦!!!虽然功能尚未完善,但是看题目的时候舒服了不少。题目描述:包含 A-Z 的字母的消息通过以下规则编码:'A' -> 1'B' -> 2...'Z' -> 26给定一个包含数字的编码消息,请确定解码方法的总数。例如,给定消息为 "12", 它可以解码为 "AB"(1 2)或 "L"(12)。"12" 的解码方法为 2 种。我的思路: ...原创 2018-03-27 11:33:56 · 226 阅读 · 0 评论 -
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 duplicate subsets.For example,If nums = [1,...原创 2018-03-26 19:16:42 · 251 阅读 · 0 评论 -
89. Gray Code
题目描述:The gray code is a binary numeral system where two successive values differ in only one bit.Given a non-negative integer n representing the total number of bits in the code, print the sequence of...原创 2018-03-26 18:51:15 · 214 阅读 · 0 评论 -
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 additi...原创 2018-03-26 17:31:34 · 180 阅读 · 0 评论 -
79. Word Search
题目描述:Given a 2D board and a word, find if the word exists in the grid.The word can be constructed from letters of sequentially adjacent cell, where "adjacent" cells are those horizontally or verticall...原创 2018-03-22 12:14:09 · 445 阅读 · 0 评论 -
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:[ [3],...原创 2018-03-22 11:03:38 · 227 阅读 · 0 评论 -
77. Combinations
题目描述:Given two integers n and k, return all possible combinations of k numbers out of 1 ... n.For example,If n = 4 and k = 2, a solution is:[ [2,4], [3,4], [2,3], [1,2], [1,3], [1,4],]我的思...原创 2018-03-21 12:18:34 · 220 阅读 · 0 评论 -
75. Sort Colors
题目描述:Given an array with n objects colored red, white or blue, sort them so that objects of the same color are adjacent, with the colors in the order red, white and blue.Here, we will use the integers...原创 2018-03-21 09:54:19 · 228 阅读 · 0 评论 -
47. Permutations II
题目描述:Given a collection of numbers that might contain duplicates, return all possible unique permutations.For example,[1,1,2] have the following unique permutations:[ [1,1,2], [1,2,1], [2,1,1]]...原创 2018-03-11 11:23:58 · 153 阅读 · 0 评论 -
46. Permutations
题目描述:Given a collection of distinct numbers, return all possible permutations.For example,[1,2,3] have the following permutations:[ [1,2,3], [1,3,2], [2,1,3], [2,3,1], [3,1,2], [3,2,1]]我的...原创 2018-03-11 11:01:23 · 158 阅读 · 0 评论 -
40. Combination Sum II
题目描述:Given a collection of candidate numbers (C) and a target number (T), find all unique combinations in C where the candidate numbers sums to T.Each number in C may only be used once in the combinat...原创 2018-03-10 16:07:34 · 164 阅读 · 0 评论
分享