- 博客(35)
- 收藏
- 关注
原创 NP
8.3STINGY SAT is the following problem: given a set of clauses (each a disjunction of literals) and an integer k, find a satisfying assignment in which at most k variables are true, if such an ass
2017-07-10 10:32:02 339
原创 No199. Binary Tree Right Side View
一、题目描述Given a binary tree, imagine yourself standing on theright side of it, return the values of the nodes you can see ordered from top to bottom.For example:Given the following binary tree
2017-06-25 00:58:09 196
原创 No.547. Friend Circles
一、题目描述There are N students in a class. Some of them are friends, while some are not. Their friendship is transitive in nature. For example, if A is a direct friend of B, and B is a direct friend
2017-06-24 21:48:07 232
原创 Best Time to Buy and Sell Stock系列问题
一、121. Best Time to Buy and Sell Stock1、题目描述Say you have an array for which the ith element is the price of a given stock on dayi.If you were only permitted to complete at most one transacti
2017-06-22 16:34:35 382
原创 No12&13 Integer and Roman
一、Integer to Romanpublic static String intToRoman(int num) { String M[] = {"", "M", "MM", "MMM"}; String C[] = {"", "C", "CC", "CCC", "CD", "D", "DC", "DCC", "DCCC", "CM"}; String X[] =
2017-06-21 15:49:47 187
原创 No494. 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.
2017-06-20 21:04:16 190
原创 No516. 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 lo
2017-06-20 16:39:05 188
原创 No312. Burst Balloons
一、题目描述Given n balloons, indexed from 0 to n-1. Each balloon is painted with a number on it represented by array nums. You are asked to burst all the balloons. If the you burst balloon i you
2017-06-20 15:09:03 225
原创 算法机考模拟题
一、1、题目描述Description定义超级和函数F如下:F(0, n) = n,对于所有的正整数n..F(k, n) = F(k – 1, 1) + F(k – 1, 2) + … + F(k – 1, n),对于所有的正整数k和n. 请实现下面Solution类中计算F(k, n)的函数(1 class Solution {public:
2017-06-19 15:39:36 1274 5
原创 No1090. Highways
一、题目描述DescriptionThe island nation of Flatopia is perfectly flat. Unfortunately, Flatopia has no public highways. So the traffic is difficult in Flatopia. The Flatopian government is aware
2017-06-07 00:26:01 236
原创 No323. Number of Connected Components in an Undirected Graph
一、题目描述Given n nodes labeled from 0 to n - 1 and a list of undirected edges (each edge is a pair of nodes), write a function to find the number of connected components in an undirected graph.
2017-06-06 21:16:17 261
原创 No1154. Easy sort
一、题目描述DescriptionYou know sorting is very important. And this easy problem is:Given you an array with N non-negative integers which are smaller than 10,000,000, you have to sort this array.
2017-06-06 19:46:41 205
原创 No215. Kth Largest Element in an Array
一、题目描述Find the kth largest element in anunsorted array. Note that it is the kth largest element in the sorted order,not the kth distinct element.For example,Given [3,2,1,5,6,4] and k = 2, retu
2017-06-05 12:39:47 232
原创 No1031.Campus
一、题目描述DescriptionAt present, Zhongshan University has 4 campuses with a total area of 6.17 square kilometers sitting respectively on both sides of the Pearl River or facing the South China S
2017-06-01 16:21:55 261
原创 No210. 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 e
2017-05-26 22:29:07 221
原创 No207. 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 e
2017-05-26 09:05:17 222
原创 No399. Evaluate Division
一、题目描述Equations are given in the format A / B = k, where A and B are variables represented as strings, and k is a real number (floating point number). Given some queries, return the answers. I
2017-05-24 18:27:00 238
原创 No241. Different Ways to Add Parentheses
一、题目描述Given a string of numbers and operators, return all possible results from computing all the different possible ways to group numbers and operators. The valid operators are +, - and *.二、主要思
2017-05-17 11:09:21 251
原创 No.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
2017-04-24 23:26:39 277
原创 N0413. Arithmetic Slices
一、问题描述A sequence of number is called arithmetic if it consists of at least three elements and if the difference between any two consecutive elements is the same.A zero-indexed array A cons
2017-04-20 22:01:42 290
原创 No104. 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.二、基本思路设一个全局变量的depth作为当前深度的统计
2017-04-19 00:19:48 190
原创 No515. Find Largest Value in Each Tree Row
一、题目描述:You need to find the largest value in each row of a binary tree. 二、思路:BFS搜索整棵树,用队列存储树的节点,从第一行(即根节点)开始,每读取本行节点的子节点时,只要非空就将子节点加入队列,同时记录下一行的非空子节点的个数,这样在遍历子节点该行的时候,就明确从队列中取出多少个节点进行比较他们的val值。遍
2017-04-16 09:39:30 418
原创 No.530 Minimum Absolute Difference in BST
1、问题描述:Given a binary search tree with non-negative values, find the minimum absolute difference between values of any two nodes.2、解题思路:根据题目给出的例子是相邻两个节点比大小,(我一开始还以为是任意两个点比大小,尴尬~)通过先序遍历,读取根节点的数值,然后
2017-04-15 11:17:49 280
原创 No.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 siz
2017-03-26 21:18:07 242
原创 No.406 Queue Reconstruction by Height
贪心算法:在所有人中先挑选出身高最高的人们,对他们进行排序,然后从剩余的人里挑选身高最高的插入有序数组中,由于后进来的人身高比前进来的人身高矮,所以不会影响每个人的第二个参数。class Solution {public: vector> reconstructQueue(vector>& people) { sort(people.begin(),people.en
2017-03-24 15:41:00 203
原创 No.513 Find Bottom Left Tree Value
思路一:利用BFS将整个数组遍历,求出最底层最左边的节点,将该节点输出。在实现过程中利用队列数据结构实现,由于给定的树的节点的数据结构中没有记录层数的成员,所以同时创建一个记录层数的队列进行相同的操作。注意当层数发生第一次变化时,即每一层最左边的节点,记录该节点。class Solution {public: int findBottomLeftValue(TreeNode* r
2017-03-22 00:02:50 180
原创 vector学习笔记
一、概述1、集合中的每个对象都有一个与之对应的索引,索引用于访问对象。2、使用vector必须包含头文件:#include3、vector能容纳绝大多数的对象作为其元素,但是因为引用不是对象,所以不存在包含引用的vector。二、使用(1)定义vector ivec;vector> file;(2)初始化vector v1; //创建了一个空vectorv
2017-03-11 21:20:45 234
原创 No.50 Pow
1、思路一:根据n的取值分三种情况,n>0、n==0和nclass Solution {public: double myPow(double x, int n) { double mul =1; if(n==0){ return 1; } else if(n>0){
2017-03-10 21:23:18 189
原创 No.169 Majority Element
思路一(1)首先将给定的数组排序,使得数组的元素从小到大排列,相同的元素处于相邻的位置,然后计算相同元素的个数,如果不足n/2,则计算下一个数的个数,如果超过n/2,则返回该元素。class Solution {public: int majorityElement(vector& nums) { sort(nums.begin(),nums.end());
2017-03-10 21:13:51 188
原创 关联容器(map和set)
关联容器(map和set)关联容器共有8个:map、set、multimap、multiset、unordered_map、unordered_set、unordered_multimap、unordered_multiset。每个容器(1)是一个set或是一个map(2)不重复关键字(无multi)或有重复关键字(有multi)(3)按顺序保存元素(无unordered)或无序保存元素(
2017-02-26 16:57:30 299
原创 LeetCode No.461 Hamming Distance
1、我的解法(C++)class Solution {public: int hammingDistance(int x, int y) { int a = x^y; int num=0; while(a>=1){ if(a%2==1) num++; a/=2; }
2017-02-25 17:26:44 171
原创 LeetCode No.70 Climbing Stairs
LeetCode No.70 Climbing Stairs 深入理解并灵活运用fibonacci数列
2017-02-22 23:23:04 214
原创 LeetCode No.1 Two Sum
1、indices ['ɪndɪsiːz]n. 指数;目录(index的复数) 2、vector的操作(1)创建vector对象 vector vec;(2)使用下标访问元素 vector[0](3)尾部插入元素a vector.push_back(a);(4)用迭代器在第i+1个元素前面插入元素a vector.insert(vec.begin(
2017-02-21 22:17:27 331
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人