- 博客(45)
- 收藏
- 关注
原创 第十九周:课后习题8.8
解: 对于任意一个3SAT实例: 若其中某个子句中包含了同一个文字多次,则可以将这些相同的文字合并为一次; 若某个变量同时包含了true和false,则该变量可以去掉。 因此,在每个子句中添加一些没用的辅助变量,这样就可以将每个子句中包含的文字数目扩充到四个。 即将3SAT实例转化成了一个EXACT 4SAT问题。 这就通过将3SAT归约到
2017-07-03 22:27:48 249
原创 第十八周:[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. The r
2017-06-28 18:14:08 209
原创 第十八周:[Leetcode]111. Minimum Depth of Binary Tree
Given a binary tree, find its minimum depth. The minimum depth is the number of nodes along the shortest path from the root node down to the nearest leaf node.和求最大距离不一样,因为是求到叶子节点的最小距离,需要区分左右子树有可能为空的情况
2017-06-28 18:10:43 195
原创 第十八周:[Leetcode]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.dfs进行递归。class Solution {public: int
2017-06-28 18:04:24 206
原创 第十八周:[Leetcode]240. Search a 2D Matrix II
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 in ascending from left to right. Integers in each
2017-06-28 17:37:02 175
原创 第十八周:[Leetcode]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 row
2017-06-28 17:32:47 185
原创 第十七周:[Sicily]机考模拟题1000-1006
1000.函数求值:直接暴力模拟即可。class Solution {public: int F(int k, int n) { int ans[15][15] = {0}; int i,j,kk,cur; for(i = 0;i <= n;i++) ans[0][i] = i; for(i = 1;i <= k;i++)
2017-06-18 00:33:23 271
原创 第十六周:[Sicily]1321. Robot
Description Karell Incorporated has designed a new exploration robot that has the ability to explore new terrains, this new robot can move in all kinds of terrain, it only needs more fuel to move in r
2017-06-06 21:40:40 350
原创 第十五周:[Sicily]1504. Slim Span
就是求给出的图中,所有生成树中最大权值边与最小权值边的差的最小值。首先将所有边按照权值升序排序,然后从权值最小的边开始用kruskal法求最小生成树,因为以该边开始的最小生成树,得到的最大权值边与最小权值边的差值肯定是以该边开始的生成树里最小的。因此就转换成了以不同边开始求最小生成树的问题。然后继续求以权值第二小的边开始的最小生成树。。。一直求到以权值第m-(n-1)大的边开始的最小生成树(因为最小
2017-06-04 22:54:51 195
原创 第十四周:[LeetCode]10. Regular Expression Matching
Implement regular expression matching with support for ‘.’ and ‘*’.‘.’ Matches any single character. ‘*’ Matches zero or more of the preceding element.The matching should cover the entire input string
2017-06-03 21:22:39 220
原创 第十三周:[Sicily]1423. 魔王bug的2色定理
Description 背景: 传说中魔王bug被杀时留下了一股神秘的力量,但是同时也留下了一个具难的题目,如果你能解答这个 具难的题目,你就能获得bug魔王留下的神秘力量…… 题目描述: 魔王bug的难题来自于它自创的2色定理,魔王bug坚信:天地万物,有阴必有阳,有正必有负,有黑必有白, 有邪恶的魔王必有正义的天使 >_< ….. 魔王bug留下了一幅N个点M个边的图,图中有些点已
2017-05-18 23:41:35 253
原创 第十二周:[Sicily]1402. Panic Room
Description You are the lead programmer for the Securitron 9042, the latest and greatest in home security software from Jellern Inc. (Motto: We secure your stuff so YOU can’t even get to it). The sof
2017-05-16 23:28:23 182
原创 第十一周:[Leetcode]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 assum
2017-05-07 22:09:15 171
原创 第十一周:[Leetcode]474. Ones and Zeroes
In the computer world, use restricted resource you have to generate maximum benefit is what we always want to pursue. For now, suppose you are a dominator of m 0s and n 1s respectively. On the other h
2017-05-07 21:55:00 194
原创 第十周:[Leetcode]486. Predict the Winner
Given an array of scores that are non-negative integers. Player 1 picks one of the numbers from either end of the array followed by the player 2 and then player 1 and so on. Each time a player picks a
2017-05-01 17:19:25 414
原创 第九周:[Leetcode]494. Target Sum
You are given a list of non-negative integers, a1, a2, …, an, and a target, S. Now you have 2 symbols + and -. For each integer, you should choose one from + and - as its new symbol. Find out how many
2017-04-25 00:26:54 205
原创 第九周:[Leetcode]523. Continuous Subarray Sum
Given a list of non-negative numbers and a target integer k, write a function to check if the array has a continuous subarray of size at least 2 that sums up to the multiple of k, that is, sums up to n
2017-04-25 00:15:32 220
原创 第九周:[Leetcode]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”]. (Order does
2017-04-24 23:43:38 162
原创 第八周:[Leetcode]300. Longest Increasing Subsequence
Given an unsorted array of integers, find the length of longest increasing subsequence. For example, Given [10, 9, 2, 5, 3, 7, 101, 18], The longest increasing subsequence is [2, 3, 7, 101], therefo
2017-04-15 16:16:31 277
原创 第八周:[Leetcode]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: 4 One possible longest palindromic
2017-04-15 16:11:21 185
原创 第八周:[Leetcode]5. Longest Palindromic Substring
Given a string s, find the longest palindromic substring in s. You may assume that the maximum length of s is 1000. Example: Input: “babad” Output: “bab” Note: “aba” is also a valid answer. Exampl
2017-04-15 16:06:45 296
原创 第七周:[hihocoder]#1050 : 树中的最长路
时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 上回说到,小Ho得到了一棵二叉树玩具,这个玩具是由小球和木棍连接起来的,而在拆拼它的过程中,小Ho发现他不仅仅可以拼凑成一棵二叉树!还可以拼凑成一棵多叉树——好吧,其实就是更为平常的树而已。 但是不管怎么说,小Ho喜爱的玩具又升级换代了,于是他更加爱不释手(其实说起来小球和木棍有什么好玩的是吧= =)。小Ho手中
2017-04-10 12:22:15 293
原创 第六周:[Leetcode]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.根据有序数组生成二叉搜索树,树的根节点为有序数组的中间树,左子节点为左半部分数组的中间数,右子节点为左半部分数组的中间数。这个过程一直递归下去,即可生成二叉搜索树。class Solution {publi
2017-04-01 00:47:03 166
原创 第六周:[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 total sum o
2017-04-01 00:43:13 157
原创 第六周:[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 \ 5 All root-to-leaf paths are: [“1->2->5”, “1->3”]DFS记录路径,要注意回溯的过程中将已经访
2017-04-01 00:39:29 157
原创 第六周:[Leetcode]437. Path Sum III
You are given a binary tree in which each node contains an integer value. Find the number of paths that sum to a given value. The path does not need to start or end at the root or a leaf, but it must
2017-04-01 00:35:02 175
原创 第六周:[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 / \
2017-04-01 00:30:51 169
原创 第六周:[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 = 2
2017-04-01 00:25:42 194
原创 第六周:[Leetcode]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.同时对两棵树做DFS,对比节点的值
2017-04-01 00:22:16 173
原创 第六周:[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 at a tim
2017-04-01 00:15:58 279
原创 第五周:[Leetcode]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 you
2017-03-26 00:33:19 334
原创 第五周:[Leetcode]455. Assign Cookies
Assume you are an awesome parent and want to give your children some cookies. But, you should give each child at most one cookie. Each child i has a greed factor gi, which is the minimum size of a cook
2017-03-26 00:28:55 201
原创 第五周:[Leetcode]122. Best Time to Buy and Sell Stock II
Say you have an array for which the ith element is the price of a given stock on day i. Design an algorithm to find the maximum profit. You may complete as many transactions as you like (ie, buy one a
2017-03-26 00:24:46 181
原创 第五周:[Leetcode]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), de
2017-03-26 00:18:22 275
原创 第四周:[LeetCode]332. Reconstruct Itinerary
Given a list of airline tickets represented by pairs of departure and arrival airports [from, to], reconstruct the itinerary in order. All of the tickets belong to a man who departs from JFK. Thus, the
2017-03-18 20:19:37 220
原创 第四周:[Leetcode]210. Course Schedule II
There are a total of n courses you have to take, labeled from 0 to n - 1. Some courses may have prerequisites, for example to take course 0 you have to first take course 1, which is expressed as a pai
2017-03-18 18:12:14 169
原创 第四周:[Leetcode]207. Course Schedule
There are a total of n courses you have to take, labeled from 0 to n - 1. Some courses may have prerequisites, for example to take course 0 you have to first take course 1, which is expressed as a pai
2017-03-18 18:07:35 178
原创 第三周:[Leetcode]103. Binary Tree Zigzag Level Order Traversal
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
2017-03-11 23:40:56 147
原创 第三周:[LeetCode]107. Binary Tree Level Order Traversal II
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: Gi
2017-03-11 23:36:18 175
原创 第三周:[LeetCode]102. Binary Tree Level Order Traversal
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,nu
2017-03-11 23:15:17 170
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人