
leetcode
bemf168
这个作者很懒,什么都没留下…
展开
-
LeetCode64 minPathSum 解题报告
Given a m x n grid filled with non-negative numbers, find a path from top left to bottom right which minimizes the sum of all numbers along its path.Note: You can only move either down or right at a原创 2018-01-10 22:45:59 · 388 阅读 · 0 评论 -
LeetCode88 Merge Sorted Array 解题报告
Given two sorted integer arrays nums1 and nums2, merge nums2 into nums1 as one sorted array.题意:给定两个有序数组:nums1 和nums2,将两个数组合为一个,其中nums1有足够的空间容纳两个数组。如果不创建新的数组,那么就直接在nums1上处理,只需要在空间末尾一次次地保留nums1数组末尾和...原创 2018-03-01 11:09:11 · 161 阅读 · 0 评论 -
LeetCode92 Reverse Linked List II 解题报告
Reverse a linked list from position m to n. Do it in-place and in one-pass.example:1->2->3->4->5->6 2 51->5->4->3->2->6题意是: 给出一个链表,将位置n和m的两个点之间进行旋转(包括n, m)。不能修改节...原创 2018-03-01 12:56:02 · 168 阅读 · 0 评论 -
LeetCode50 Pow(x, n) 解题报告
题目的意思是实现一个pow 函数。Input: 2.00000, 10Output: 1024.00000这里用的是递归的办法,能够降低时间复杂度,不过需要对n进行奇数,偶数进行判断,用了&0x1进行判断,当判断n为奇数的时候,乘上x。代码如下:class Solution {public: double myPow(double x, int n) {...原创 2018-03-26 21:29:42 · 198 阅读 · 0 评论 -
LeetCode49 Group Anagrams解题报告
题意: 给一个字符串数组,将这个字符串按照组成的字母进行分组。 如["eat", "tea", "tan", "ate", "nat", "bat"], [ ["ate", "eat","tea"], ["nat","tan"], ["bat"]原创 2018-03-26 21:46:58 · 167 阅读 · 0 评论 -
LeetCode84 Largest Rectangle in Histogram 解题报告
Given n non-negative integers representing the histogram’s bar height where the width of each bar is 1, find the area of largest rectangle in the histogram.题意是:给一个连续的非负整数数组,求出该数组的直方图所能组成的面积最大的长方形。如图...原创 2018-03-27 10:43:12 · 181 阅读 · 0 评论 -
LeetCode85 Maximal Rectangle 解题报告
Given a 2D binary matrix filled with 0’s and 1’s, find the largest rectangle containing only 1’s and return its area.For example, given the following matrix:1 0 1 0 01 0 1 1 11 1 1 1 11 0 0 1...原创 2018-03-27 23:52:45 · 199 阅读 · 0 评论 -
LeetCode70 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?Input:2Output:2题意是给一个n层的阶梯,每...原创 2018-03-29 10:10:00 · 136 阅读 · 0 评论 -
LeetCode94 Binary Tree Inorder Traversal
Given a binary tree, return the inorder traversal of its nodes’ values. 1 \ 2 / 3return [1,3,2].题意就是给一个二叉树,然后返回其中序遍历的结果。 用递归其实非常简单,代码如下:class Solution {public: vec...原创 2018-04-11 20:33:22 · 147 阅读 · 0 评论 -
FD_CLOEXEC 详解
最近在看《UNIX环境高级编程》这本书 在看第三章有关文件描述符号的时候有些地方不懂,就是题目的FD_CLOEXEC标志,上网查了一些资料,这里写个博客记录下。一般来说进程往往会调用fork函数来执行一个子进程,调用execve()执行其他程序,这时候可能就导致子进程中存在一些无用的文件描述符问题。父进程在fork函数的时候,子进程会拷贝跟父进程一样的地址空间,包括寄存器,文件描述符...原创 2018-04-20 23:24:05 · 9782 阅读 · 2 评论 -
LeetCode72 Edit Distance 解题报告
Given two words word1 and word2, find the minimum number of steps required to convert word1 to word2. (each operation is counted as 1 step.)You have the following 3 operations permitted on a word:原创 2018-01-19 15:50:03 · 185 阅读 · 0 评论 -
LeetCode62 Unique Paths 解题报告
LeetCode62 Unique Paths 解题报告A robot is located at the top-left corner of a m x n grid (marked ‘Start’ in the diagram below).The robot can only move either down or right at any point in time. The r原创 2018-01-09 19:08:30 · 229 阅读 · 0 评论 -
LeetCode65 Valid Number 解题报告
Validate if a given string is numeric.Some examples:"0" => true" 0.1 " => true"abc" => false"1 a" => false"2e10" => trueNote: It is intended for the problem statement to be ambiguous. You原创 2018-01-11 20:35:39 · 205 阅读 · 0 评论 -
LeetCode67 Add Binary 解题报告
Given two binary strings, return their sum (also a binary string).For example,a = "11"b = "1"Return "100".题意是给两个二进制字符串进行相加,返回相加的值,类型为string。这类用字符串来进行求和操作,主要是要字符串相加的时候,要先从两个字符串末尾开始,然后用一个值来保原创 2018-01-11 21:16:52 · 145 阅读 · 0 评论 -
LeetCode70 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 positive原创 2018-01-12 16:30:53 · 164 阅读 · 0 评论 -
LeetCode71 Simplify Path 解题报告
Given an absolute path for a file (Unix-style), simplify it.For example,path = "/home/", => "/home"path = "/a/./b/../../c/", => "/c"题意是给一个关于路径字符串,进行简化,得到最基本的路径字符串。这是一道基于字符串的题目,同时必须知道一些路径的基本原创 2018-01-15 21:47:20 · 171 阅读 · 0 评论 -
LeetCode61 Rotate List 解题报告
LeetCode61 Rotate List 解题报告Given a list, rotate the list to the right by k places, where k is non-negative.题目的意思是: 在一个列表中找到倒数第k个的节点,然后进行旋转,即将该节点作为头节点,将该节点前的节点连接到最好的节点。例子: Given 1->2->3->4->5原创 2018-01-09 16:20:22 · 194 阅读 · 0 评论 -
LeetCode74 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 row原创 2018-01-18 18:16:04 · 198 阅读 · 0 评论 -
LeetCode83 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-01-26 17:22:05 · 176 阅读 · 0 评论 -
LeetCode82 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->2->5.Given 1->1->原创 2018-01-26 17:29:55 · 194 阅读 · 0 评论 -
LeetCode63 Unique Paths II 解题报告
Follow up for “Unique Paths”:Now consider if some obstacles are added to the grids. How many unique paths would there be?An obstacle and empty space is marked as 1 and 0 respectively in the grid.原创 2018-01-10 19:28:26 · 177 阅读 · 0 评论 -
LeetCode 236 Lowest Common Ancestor of a Binary Tree解题报告
Given a binary tree, find the lowest common ancestor (LCA) of two given nodes in the tree.According to the definition of LCA on Wikipedia: “The lowest common ancestor is defined between two nodes v ...原创 2018-04-27 11:07:22 · 265 阅读 · 0 评论