![](https://img-blog.csdnimg.cn/20201014180756724.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
算法
文章平均质量分 56
司季雨
这个作者很懒,什么都没留下…
展开
-
leetcode_2Add Two Numbers
You are given two non-empty linked lists representing two non-negative integers. The digits are stored in reverse order and each of their nodes contain a single digit. Add the two numbers and return i原创 2017-02-25 01:01:38 · 124 阅读 · 0 评论 -
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原创 2017-04-30 11:27:20 · 177 阅读 · 0 评论 -
leetcode_63. 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原创 2017-05-10 17:51:59 · 196 阅读 · 0 评论 -
leetcode_303. Range Sum Query - Immutable
题目:Given an integer array nums, find the sum of the elements between indicesi and j (i ≤ j), inclusive.Example:Given nums = [-2, 0, 3, -5, 2, -1]sumRange(0, 2) -> 1sumRange(2, 5) -> -1原创 2017-04-23 10:58:12 · 160 阅读 · 0 评论 -
leetcode_304. Range Sum Query 2D - Immutable
题目:Given a 2D matrix matrix, find the sum of the elements inside the rectangle defined by its upper left corner (row1,col1) and lower right corner (row2, col2).The above rectangle (with the原创 2017-04-23 11:26:12 · 180 阅读 · 0 评论 -
leetcode_72. Edit Distance
题目:Given two words word1 and word2, find the minimum number of steps required to convertword1 to word2. (each operation is counted as 1 step.)You have the following 3 operations permitted on a原创 2017-05-15 14:07:53 · 144 阅读 · 0 评论 -
leetcode_62. 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 robot is trying to r原创 2017-05-07 13:35:18 · 134 阅读 · 0 评论 -
leetcode_64. Minimum Path Sum
题目:Given a m x n grid filled with non-negative numbers, find a path from top left to bottom right whichminimizes the sum of all numbers along its path.跟上次的题目很像,就是多了权值条件而已。那就每个位置等于上面或者左面加自己,上面或者左原创 2017-05-10 17:26:31 · 109 阅读 · 0 评论 -
leetcode_162. Find Peak Element
题目:A peak element is an element that is greater than its neighbors.Given an input array where num[i] ≠ num[i+1], find a peak element and return its index.The array may contain multiple peaks,原创 2017-06-01 20:50:39 · 128 阅读 · 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 d原创 2017-06-01 21:03:29 · 106 阅读 · 0 评论 -
leetcode_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原创 2017-05-22 15:42:25 · 141 阅读 · 0 评论 -
leetcode_sicily
做了几道模拟题。第一道,递归。简单,不必多说。直接贴代码:int F(int k, int n) { int m = 0; if(k == 0){ return n; } else{ for(int i = 0; i <= n; ++i){ m+=F(k-1,i); } return m; }}原创 2017-06-18 16:18:16 · 181 阅读 · 0 评论 -
第八章课后题_1
8.3STINGY SAT的解是属于NP的,是可以在多项式时间内验证的。此外,SAT问题将k设为所有变量的总个数就可以规约到STINGY SAT。所以STINGY SAT是NP完全问题。8.8首先EXACT 4SAT属于NP。其次,对于3SAT实例,如果其中的某个子句中多次包含了同一个文字,就可以缩减为1次。如果包含一个变量的否定或肯定,可以去掉这个变量。这样就能把3SAT实例原创 2017-07-05 21:31:20 · 333 阅读 · 0 评论 -
第八章课后题_2
8.10(a)、令G成一个环,其顶点的数目与H顶点数目相同。(b)、令g=|V| - 1(c)、令g=子句的总数(d)、令b=a(a+1)/2,a个顶点两两相连(e)、令b=0原创 2017-07-05 23:51:13 · 221 阅读 · 0 评论 -
leetcode_112. Path Sum
Given a binary tree and a sum, determine if the tree has a root-to-leaf path such that adding up all the values along the path equals the given sum.For example:Given the below binary tree and sum原创 2017-06-28 10:49:01 · 154 阅读 · 0 评论 -
leetcode_110. Balanced Binary Tree
题目:Given a binary tree, determine if it is height-balanced.For this problem, a height-balanced binary tree is defined as a binary tree in which the depth of the two subtrees of every node ne原创 2017-06-28 11:41:21 · 122 阅读 · 0 评论 -
leetcode_ Add to List 108. Convert Sorted Array to Binary Search Tree
Given an array where elements are sorted in ascending order, convert it to a height balanced BST.将一个排好的数组转换成平衡二叉树,就是说,每次从中间分开,左边作为左子树,右边作为右子树。代码:/** * Definition for a binary tree node.原创 2017-06-28 12:01:58 · 167 阅读 · 0 评论 -
leetcode_ Add to List 121. Best Time to Buy and Sell Stock
Say you have an array for which the ith element is the price of a given stock on day i.If you were only permitted to complete at most one transaction (ie, buy one and sell one share of the stock), d原创 2017-06-28 13:58:41 · 151 阅读 · 0 评论 -
leetcod_516. Longest Palindromic Subsequence
题目:Given a string s, find the longest palindromic subsequence's length in s. You may assume that the maximum length of s is 1000.Example 1:Input:"bbbab"Output:4One possible longe原创 2017-04-10 14:24:43 · 165 阅读 · 0 评论 -
leetcode_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原创 2017-04-10 12:24:15 · 211 阅读 · 0 评论 -
leedcode_100. Same Tree
题目:Given two binary trees, write a function to check if they are equal or not.Two binary trees are considered equal if they are structurally identical and the nodes have the same value.原创 2017-04-10 10:29:28 · 121 阅读 · 0 评论 -
leetcode_169. Majority Element
题目:Given an array of size n, find the majority element. The majority element is the element that appearsmore than ⌊ n/2 ⌋ times.You may assume that the array is non-empty and the majority elem原创 2017-03-04 14:09:13 · 120 阅读 · 0 评论 -
leetcode_1twosum
题目: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 us原创 2017-02-25 23:12:43 · 112 阅读 · 0 评论 -
leetcode_3Longest Substring Without Repeating Characters
题目:Given a string, find the length of the longest substring without repeating characters.Examples:Given "abcabcbb", the answer is "abc", which the length is 3.Given "bbbbb", the an原创 2017-02-26 00:30:58 · 123 阅读 · 0 评论 -
leetcode_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,-原创 2017-03-19 00:22:42 · 146 阅读 · 0 评论 -
leetcode_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 d原创 2017-03-19 20:41:58 · 257 阅读 · 0 评论 -
leetcode_66. Plus One
题目:Given a non-negative integer represented as a non-empty array of digits, plus one to the integer.You may assume the integer do not contain any leading zero, except the number 0 itself.The d原创 2017-03-19 21:49:02 · 155 阅读 · 0 评论 -
leetcode_67. Add Binary
题目: Given two binary strings, return their sum (also a binary string).For example,a = "11"b = "1"Return "100". 用一想就能想到的想法,有点笨,但好想,贴代码:class Solution {public: string addBinary(string原创 2017-03-19 23:26:06 · 129 阅读 · 0 评论 -
leetcode_257. Binary Tree Paths
题目:Given a binary tree, return all root-to-leaf paths.For example, given the following binary tree: 1 / \2 3 \ 5All root-to-leaf paths are:["1->2->5", "1->3"]原创 2017-03-09 22:40:32 · 132 阅读 · 0 评论 -
leetcode_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 posi原创 2017-03-22 11:29:09 · 166 阅读 · 0 评论 -
leetcode_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.简单的指针操作。指针操作一直不太原创 2017-03-22 11:58:47 · 113 阅读 · 0 评论 -
leetcode_9. Palindrome Number
题目:Determine whether an integer is a palindrome. Do this without extra space.提示里说了要看负数是不是。原来负数都按不是。于是很简单,反过来然后看看和原来是不是相等就行了。直接贴代码吧class Solution {public: bool isPalindrome(int x) {原创 2017-03-12 22:56:24 · 149 阅读 · 0 评论 -
leetcode_14. Longest Common Prefix
题目:Write a function to find the longest common prefix string amongst an array of strings.挺简单的,就是找到共同的最长前缀。我这个方法肯定浪费空间了,但是第一个想法就这么想的那就这么做了。其实两个for循环中外面的循环可以直接拿第一个元素的size来循环的。每次取这个前缀的大小多一。如果不是所有都成功那前缀原创 2017-03-13 00:03:54 · 128 阅读 · 0 评论 -
leetcode_26. Remove Duplicates from Sorted Array
题目:Given a sorted array, remove the duplicates in place such that each element appear onlyonce and return the new length.Do not allocate extra space for another array, you must do this in plac原创 2017-03-13 15:15:34 · 165 阅读 · 0 评论 -
leetcode_35. Search Insert Position
题目:Given a sorted array and a target value, return the index if the target is found. If not, return the index where it would be if it were inserted in order.You may assume no duplicates in the a原创 2017-03-13 16:08:37 · 135 阅读 · 0 评论 -
leetcode_38. Count and Say
题目:The count-and-say sequence is the sequence of integers beginning as follows:1, 11, 21, 1211, 111221, ...1 is read off as "one 1" or 11.11 is read off as "two 1s" or 21.21 is read off as原创 2017-03-13 17:08:58 · 154 阅读 · 0 评论 -
leetcode_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 h原创 2017-03-30 22:01:08 · 96 阅读 · 0 评论 -
leetcode_107. Binary Tree Level Order Traversal II
Given a binary tree, return the bottom-up level order traversal of its nodes' values. (ie, from left to right, level by level from leaf to root).For example:Given binary tree [3,9,20,null,null,15,原创 2017-06-28 15:25:12 · 161 阅读 · 0 评论