- 博客(114)
- 收藏
- 关注
原创 最近一些练习
1.#include<iostream>#include<vector>#include<algorithm>#include<climits>using namespace std;int dfs(vector<int>& h, int j0, int j1, int j2, int cur) { in...
2018-03-16 15:25:18 252
原创 牛客网-腾讯编程题
1 编码题目描述假定一种编码的编码范围是a ~ y的25个字母,从1位到4位的编码,如果我们把该编码按字典序排序,形成一个数组如下: a, aa, aaa, aaaa, aaab, aaac, … …, b, ba, baa, baaa, baab, baac … …, yyyw, yyyx, yyyy 其中a的Index为0,aa的Index为1,aaa的Index为2,以此类推。 ...
2018-03-14 16:44:39 1203
原创 23. Merge k Sorted Lists
题目Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity.题意合并k个有序链表成1个有序链表分析将合并k个成1个链表 分解为: k个链表两两合并, 之后得到的k’链表再两两合并,直到最后只剩下一个链表实现class S
2018-01-07 13:44:19 234
原创 4. Median of Two Sorted Arrays
题目There are two sorted arrays nums1 and nums2 of size m and n respectively.Find the median of the two sorted arrays. The overall run time complexity should be O(log (m+n)).Example 1:nums1 = [1, 3]nums
2018-01-07 12:11:42 180
原创 ex.8.3
题目STINGY SAT is the following problem:given a set of clauses(each a disjunction of literals) and an integer k, find a satisfy assignment in which at most k variables are true, if such an assignment exi
2018-01-01 19:23:47 173
原创 695. Max Area of Island
题目Given a non-empty 2D array grid of 0’s and 1’s, an island is a group of 1’s (representing land) connected 4-directionally (horizontal or vertical.) You may assume all four edges of the grid are surro
2017-12-28 19:55:39 139
原创 100. Same Tree
题目Given two binary trees, write a function to check if they are the same or not.Two binary trees are considered the same if they are structurally identical and the nodes have the same value.Example 1:I
2017-12-25 20:32:07 145
原创 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 ti
2017-12-25 19:53:24 160
原创 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.题意分析实现/** * Definition for a binary tree
2017-12-25 19:26:15 139
原创 515. Find Largest Value in Each Tree Row
题目You need to find the largest value in each row of a binary tree.Example: Input: 1 / \ 3 2 / \ \ 5 3 9 Output: [1, 3, 9]题意分析实现/**/** * Definition for a binary tree no
2017-12-25 19:22:23 124
原创 513. Find Bottom Left Tree Value
题目Given a binary tree, find the leftmost value in the last row of the tree.Example 1: Input: 2 / \1 3Output: 1 Example 2: Input: 1 / \ 2 3 / / \4 5 6 / 7Output: 7 N
2017-12-25 19:14:39 151
原创 746. Min Cost Climbing Stairs
题目题意cost数组存放了每一级楼梯的花费, 要经过这一级就要付出相应的花费, 每次可以走1~2级, 可以选择从第0级和第1级开始走, 问走到顶(n)的最少花费是多少?(级数从0开始编号,对应开销cost[0])分析一些转化: 可以选择从第0级和第1级开始走->加一个第-1级,cost为0,从-1级出发 走到顶(n)->加一个第n级, cost为0, 走到第n级才算走完(前一步可以是n-1或者n
2017-12-24 23:51:24 197
原创 638. Shopping Offers
题目题意不同的商品i有不同需求needs[i] 有些特价组合special[],对应每一种商品i有相应的数量,买相应的数量就可以用组合价(但是有一些组合未必会比单买便宜) 求恰好买够需求needs[]的的最低总价.分析用动态规划+DFS 每一次调用遍历一次组合special[i], 看剩余的需求里面能不能用组合i的方式购买,如果可以,则使用组合i,并且减去相应的need的数量,剩余的数量再调用
2017-12-24 23:51:00 351
原创 LL(1)语法分析器 c++实现
结构记号和规定代码Base.hBase.cppLL1.hLL1.cppmain.cpp测试样例结构main.cpp包含了主函数和LL1语法分析过程的调用 Base.h和Base.cpp定义了类Base, 类Base用于存储产生式、符号表、FIRST集合FOLLOW集(还可应用于LR分析,故独立出来)LL1.h和LL1.cpp定义了类LL...
2017-12-18 20:21:00 21618 6
原创 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 gr...
2017-12-17 22:54:07 136
原创 740. Delete and Earn
题目Given an array nums of integers, you can perform operations on the array.In each operation, you pick any nums[i] and delete it to earn nums[i] points. After, you must delete every element equal ...
2017-12-17 22:53:12 160
原创 238. Product of Array Except Self
题目Given an array of n integers where n > 1, nums, return an array output such that output[i] is equal to the product of all the elements of nums except nums[i].Solve it without division and in O(n).For
2017-12-17 22:51:23 157
原创 152. Maximum Product Subarray
题目Find the contiguous subarray within an array (containing at least one number) which has the largest product.For example, given the array [2,3,-2,4], the contiguous subarray [2,3] has the larges...
2017-12-17 22:50:27 133
原创 309. Best Time to Buy and Sell Stock with Cooldown
题目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-12-10 21:03:40 144
原创 416. Partition Equal Subset Sum
题目Given a non-empty array containing only positive integers, find if the array can be partitioned into two subsets such that the sum of elements in both subsets is equal.Note: Each of the array elemen
2017-12-03 11:51:45 151
原创 213. House Robber II
题目Note: This is an extension of House Robber.After robbing those houses on that street, the thief has found himself a new place for his thievery so that he will not get too much attention. This time, a
2017-12-03 11:09:43 128
原创 377. Combination Sum IV
题目Given an integer array with all positive numbers and no duplicates, find the number of possible combinations that add up to a positive integer target.Example:nums = [1, 2, 3]target = 4The possible c
2017-11-25 20:45:47 244
原创 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-11-25 20:36:34 158
原创 64. Minimum Path Sum
题目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 an
2017-11-25 20:31:06 113
原创 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-11-25 20:21:37 135
原创 91. Decode Ways
题目A message containing letters from A-Z is being encoded to numbers using the following mapping:'A' -> 1'B' -> 2...'Z' -> 26Given an encoded message containing digits, determine the total number of
2017-11-25 20:05:07 130
原创 303. Range Sum Query - Immutable
题目Given an integer array nums, find the sum of the elements between indices i and j (i ≤ j), inclusive.Example:Given nums = [-2, 0, 3, -5, 2, -1]sumRange(0, 2) -> 1sumRange(2, 5) -> -1sumRange(0, 5)
2017-11-25 20:01:08 133
原创 198. House Robber
题目You are a professional robber planning to rob houses along a street. Each house has a certain amount of money stashed, the only constraint stopping you from robbing each of them is that adjacent hous
2017-11-25 19:55:40 125
原创 718. Maximum Length of Repeated Subarray
题目Given two integer arrays A and B, return the maximum length of an subarray that appears in both arrays.Example 1:Input:A: [1,2,3,2,1]B: [3,2,1,4,7]Output: 3Explanation: The repeated subarray wit
2017-11-25 19:47:14 162
原创 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 positive in
2017-11-18 22:19:37 152
原创 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-11-18 21:09:40 128
原创 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 reach the bot
2017-11-17 22:21:56 170
原创 121. Best Time to Buy and Sell Stock
题目题意找到 max(nums[j] - nums[i]) , j > i && nums[j] > nums[i]max(nums[j] - nums[i]) , j&nbs
2017-11-16 23:54:14 128
原创 312. Burst Balloons
题目题意炸掉i处的气球能获得nums[i−1]∗nums[i]∗nums[i+1]nums[i-1]*nums[i]*nums[i+1], 用过的气球就没有了, 可以将最左端和最右端看作有一个额外的1, 求总收益的最大值分析参考了这里有例子分析依次遍历不同长度len的子串s[left, right] (left∈[0, n -len], right = left+len-1);用k∈[left,
2017-11-16 21:27:22 122
原创 516. Longest Palindromic Subsequence
题目题意求数组的回文子序列的最长长度分析用f[i][j]f[i][j]表示从i到j的回文子序列的最长长度 转移方程如下 如果s[i]==s[j]s[i] == s[j], f[i][j]=f[i+1][j−1]+2f[i][j] = f[i+1][j-1] +2 如果s[i]!=s[j]s[i] != s[j], f[i][j]=max(f[i][j−1],f[i+1][j])f[i][j]
2017-11-16 20:43:27 161
原创 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-11-16 11:55:54 189
原创 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 tim
2017-11-08 14:14:52 139
原创 357. Count Numbers with Unique Digits
题目Given a non-negative integer n, count all numbers with unique digits, x, where 0≤x<10n0 ≤ x < 10^n.Example: Given n = 2, return 91. (The answer should be the total numbers in the range of 0 ≤ x < 10
2017-11-08 11:13:37 123
原创 343. Integer Break
题目Given a positive integer n, break it into the sum of at least two positive integers and maximize the product of those integers. Return the maximum product you can get.For example, given n = 2, return
2017-11-08 10:34:53 108
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人