算法作业
文章平均质量分 66
林晓健
这个作者很懒,什么都没留下…
展开
-
算法设计与分析HW1:LeetCode7
Description: Reverse digits of an integer. Example 1: Input:123 Output:321 Example 2: Input:-123 Output:-321 Note: The input is assumed to be a 32-bit signed integer. Your functio原创 2017-02-28 12:07:29 · 463 阅读 · 0 评论 -
算法作业HW18:LeetCode102 Binary Tree Level Order Traversal
Description: Given a binary tree, return the level order traversal of its nodes' values. (ie, from left to right, level by level). Note: For example: Given binary tree [3,9,20,原创 2017-06-25 11:04:39 · 284 阅读 · 0 评论 -
算法作业HW20 202. Happy Number
Description: Write an algorithm to determine if a number is "happy". A happy number is a number defined by the following process: Starting with any positive integer, replace the number原创 2017-06-25 11:57:01 · 180 阅读 · 0 评论 -
算法作业HW19 130. Surrounded Regions
Description: 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.原创 2017-06-25 11:12:47 · 296 阅读 · 0 评论 -
算法作业HW23:LeetCode 31 Next Permutation
Description: Implement next permutation, which rearranges numbers into the lexicographically next greater permutation of numbers. If such arrangement is not possible, it must rearrange原创 2017-07-04 19:55:17 · 202 阅读 · 0 评论 -
算法作业HW24:LeetCode 24 Submission Details
Description: Given a linked list, swap every two adjacent nodes and return its head. Note: For example, Given 1->2->3->4, you should return the list as 2->1->4->原创 2017-07-04 19:56:08 · 194 阅读 · 0 评论 -
算法作业:证明题(1)-- 8.3
题目描述: 证明: ∵STINGY SAT的解已知是在多项式时间内可验证 ∴STINGY SAT是属于NP问题 ∵通过将k设定为所有变量的总数,就可以把SAT 规约到STINGY SAT问题 ∴STINGY SAT也为NP完全问题原创 2017-07-04 20:39:08 · 241 阅读 · 0 评论 -
算法作业HW25:LeetCode 26. Remove Duplicates from Sorted Array
Description: Given a sorted array, remove the duplicates in place such that each element appear only once and return the new length. Do not allocate extra space for another array, you must do this原创 2017-07-06 00:45:29 · 139 阅读 · 0 评论 -
算法作业HW26:LeetCode 27. Remove Element
Description: Given an array and a value, remove all instances of that value in place and return the new length. Do not allocate extra space for another array, you must do this in place with原创 2017-07-06 00:45:40 · 206 阅读 · 0 评论 -
算法作业:证明题(2)-- 8.8
问题描述: 证明:原创 2017-07-04 20:41:48 · 331 阅读 · 0 评论 -
算法作业:证明题(3)-- 8.10
问题描述: 证明: a) b)使g=|V|-1,可得到一个Rudrata路径 c)让g表示为子句的总数可得 d)使a*(a-1)/2 = b,这时候可成最大团问题,因为这使得a个顶点两两之间相互连接 e)要成最大独立子集问题,只需使b=0 f)对应了最小顶点集覆盖的推广 g)原创 2017-07-06 01:38:03 · 239 阅读 · 0 评论 -
算法作业HW27:LeetCode 28. Implement strStr()
Description: Implement strStr(). Returns the index of the first occurrence of needle in haystack, or -1 if needle is not part of haystack. Note: 无 S原创 2017-07-06 19:58:00 · 176 阅读 · 0 评论 -
算法作业HW28:LeetCode 100. Same Tree
Description: 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原创 2017-07-06 20:11:42 · 202 阅读 · 0 评论 -
算法作业:证明题(4)-- 8.12
问题陈述: 证明: a)∵给定一个图G的待定生成树,遍历生成树的每一个节点,检查每个点的度数是否小于等于k,可判定其是否满足k-生成树,判定过程时间复杂度O(V) ∴ k-生成树问题是一个搜索问题 b) ∵需要找到生成的树是否符合要求,检查需要遍历生成树的每一个节点,检查每个点的度数,这一步是时间复杂度是多项式,为V+E ∴k-生成树为NP问题 ∵通过Rudr原创 2017-07-06 20:42:05 · 264 阅读 · 0 评论 -
算法作业:证明题(5)-- 8.12
问题摘要: 证明如下问题是NP-完全问题,给定一个无向图G=(V,E)和整数k,求G中一个规模为k的团以及一个规模为k的独立集 证明: a)对于团,因为对于V的子集V’,其每一对节点是由边集一条边相连,则团为G完全子图。又对于一个给定图G,对于顶点子集V’的任一对顶点(u,v),判断其是否属于E,可在多项式事件确定V’是否为团 设φ= C1∧C2∧C3...∧Ck为3-CNF中一个原创 2017-07-06 22:16:06 · 696 阅读 · 0 评论 -
算法作业HW29:LeetCode 219. Contains Duplicate II
Description: Given an array of integers and an integer k, find out whether there are two distinct indices i and j in the array Note: such that nums[i] = nums[j] and the absolu原创 2017-07-06 20:23:57 · 237 阅读 · 0 评论 -
算法作业HW17:LeetCode101 Symmetric Tree
Description: 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: Note:原创 2017-06-25 10:52:30 · 207 阅读 · 0 评论 -
算法作业HW21:LeetCode 18 4Sum
Description: Given an array S of n integers, are there elements a, b, c, and d in S such that a + b + c + d = target? Find all unique quadruplets in the array which gives the sum of target.原创 2017-07-03 19:57:13 · 198 阅读 · 0 评论 -
算法作业HW16:LeetCode121 Best Time to Buy and Sell Stock
Description: 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原创 2017-06-12 09:31:42 · 208 阅读 · 0 评论 -
算法设计与分析HW2:LeetCode35
Description: 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 duplic原创 2017-03-06 18:43:27 · 266 阅读 · 0 评论 -
算法设计与分析HW4:LeetCode5
Description: Given a string s, find the longest palindromic substring in s. You may assume that the maximum length of s is 1000. Note: “aba” is also a valid answer when you input "原创 2017-03-20 12:06:14 · 294 阅读 · 0 评论 -
算法设计与分析HW3:LeetCode3
Description: Given a string, find the length of the longest substring without repeating characters. Note: Note that the answer must be a substring, not a subsequence. Sol原创 2017-03-13 19:49:19 · 336 阅读 · 0 评论 -
算法设计与分析 HW6:LeetCode 54
Description: Given a matrix of m x n elements (m rows, n columns), return all elements of the matrix in spiral order. Note: For example, Given the following matrix: [ [ 1, 2, 3 ]原创 2017-04-10 19:32:56 · 343 阅读 · 0 评论 -
算法设计与分析HW5:LeetCode77
Description: Given two integers n and k, return all possible combinations of k numbers out of 1 ... n. Note: For example, If n = 4 and k = 2, a solution is: [ [2,4], [3,4],原创 2017-03-27 01:17:17 · 260 阅读 · 0 评论 -
算法设计与分析HW7:LeetCode56.Merge Intervals
Description: 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]. Solution:原创 2017-04-17 02:10:45 · 328 阅读 · 0 评论 -
算法作业HW14:Leetcode20 Valid Parentheses
Description: Given a string containing just the characters '(', ')', '{', '}', '[' and ']', determine if the input string is valid. Note: The brackets must close in the correct order, "()"原创 2017-05-23 01:10:52 · 220 阅读 · 0 评论 -
算法设计与分析HW8:LeetCode71.Simplify Path
Description: Given an absolute path for a file (Unix-style), simplify it. Note: For example, path = "/home/", => "/home" path = "/a/./b/../../c/", => "/c" Solutio原创 2017-04-25 00:24:59 · 346 阅读 · 0 评论 -
算法作业HW9:LeetCode93 Restore IP Addresses
Description: Given a string containing only digits, restore it by returning all possible valid IP address combinations. Note: For example: Given "25525511135",return ["255.255.11.135原创 2017-05-07 16:46:15 · 220 阅读 · 0 评论 -
算法作业HW10:Leetcode92 Reverse Linked List II
Description: Reverse a linked list from position m to n. Do it in-place and in one-pass. Note: For example: Given 1->2->3->4->5->NULL, m = 2 and n = 4, return 1->4->3->2->5->NULL.原创 2017-05-07 19:24:36 · 227 阅读 · 0 评论 -
算法作业HW15:LeetCode187 Repeated DNA Sequences
Description: All DNA is composed of a series of nucleotides abbreviated as A, C, G, and T, for example: "ACGAATTCCG". When studying DNA, it is sometimes useful to identify repeated sequences wi原创 2017-06-06 10:20:32 · 330 阅读 · 0 评论 -
算法作业HW11:Leetcode90 Path Sum
Description: 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. Note: Given the below原创 2017-05-22 00:21:04 · 176 阅读 · 0 评论 -
算法作业HW12:Leetcode94 Sum Root to Leaf Numbers
Description: 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原创 2017-05-22 00:20:55 · 305 阅读 · 0 评论 -
算法作业HW13:Leetcode96 Unique Binary Search Trees
Description: Given n, how many structurally unique BST’s (binary search trees) that store values 1…n? Note: For example, Given n = 3, there are a total of 5 unique BST's. 1原创 2017-05-22 01:31:37 · 192 阅读 · 0 评论 -
算法作业HW30:LeetCode 235. Lowest Common Ancestor of a Binary Search Tree
Description: Given a binary search tree (BST), find the lowest common ancestor (LCA) of two given nodes in the BST. Note: According to the definition of LCA on Wikipedia: “The原创 2017-07-06 20:34:07 · 182 阅读 · 0 评论