leecode第七十八题(子集)】的更多相关文章

class Solution { public: vector<vector<int>> subsets(vector<int>& nums) { vector<int> bool_num; vector<vector<int>> res; int len=nums.size(); )//特殊情况处理 return res; ;i<len;i++)//建立一个全零,长度为len的数组,用于模拟二进制加法,其中的1提供索引…
class Solution { public: void sort_list(ListNode* head1, ListNode* head2,int len)//在原链表上进行排序 { ListNode* cur_node1 = head1; ListNode* cur_node2 = head1; while (cur_node2->next != head2) cur_node2 = cur_node2->next; if (cur_node1->val > cur_nod…
你和你的朋友,两个人一起玩 Nim游戏:桌子上有一堆石头,每次你们轮流拿掉 1 - 3 块石头. 拿掉最后一块石头的人就是获胜者.你作为先手. 你们是聪明人,每一步都是最优解. 编写一个函数,来判断你是否可以在给定石头数量的情况下赢得游戏. 示例: 输入: 4 输出: false 解释: 如果堆中有 4 块石头,那么你永远不会赢得比赛:   因为无论你拿走 1 块.2 块 还是 3 块石头,最后一块石头总是会被你的朋友拿走. class Solution: def canWinNim(self,…
早上7点起床,又写了一篇小说发在了起点网上,有兴趣的可以看看.点击这里 忙完后,继续练习,刚开始发现自己答题的速度有些慢,可能是因为对于html,javascript知识不是很精通,但是话又说回来,谁又能一开始就将所有的知识一下子就掌握的很熟练呢? 第六题. 题目: function escape(s) { // Slightly too lazy to make two input fields. // Pass in something like "TextNode#foo" va…
长夜漫漫无心睡眠,来一篇嘿嘿.我相信如果已经用Shell脚本完成IOS和Android打包的朋友一定需要Jenkins 怎么才能让策划打包ipa和apk?怎么才能彻底省去程序的时间,只要在同一局域网内不需要unity的开发环境,只要它有浏览器,它就能打包Jenkins无疑是最佳选择. Unity3D研究院之IOS全自动编辑framework.plist.oc代码(六十七) Unity3D研究院之IOS全自动打包生成ipa(六十八) Unity3D研究院之Android全自动打包生成apk(六十九…
前面(第七十五.七十六篇)讲述了如何通过CoreLocation获取位置,授权.获取等相当复杂,如果借助于第三方框架,可以简单的实现授权与定位. 首先在GitHub中搜索LocationManager下载INTULocationManager,然后将其中的INTULocationManager文件夹拖入到自己的工程,导入主头文件: #import "INTULocationManager.h" 如果是iOS8,仍然需要在info.plist中加入两个键值: NSLocationAlwa…
class Solution { public: void merge(vector<int>& nums1, int m, vector<int>& nums2, int n) { ) return; ) { ;i<n;i++) nums1[i]=nums2[i];//不用push_back是因为这nums1后面有0 return; } ;i<n;i++)//先把它复制过来 nums1[m+i]=nums2[i]; ; ;i<n;i++) { w…
class Solution { public: int climbStairs(int n) { vector<unsigned long long> num;//斐波那契数列 num.push_back(); num.push_back();//头两个单独设置 ;i<n;i++)//使用循环而不是递归,节省内存和时间 num.push_back(num[i-]+num[i-]); ]; } }; 分析; 就知道三行的递归过不去,用数组也没差啦,只不过用unsigned long lo…
class Solution { public: vector<int> productExceptSelf(vector<int>& nums) { int len=nums.size(); vector<int> res; ,temp=;i<len;i++)//把前面的乘起来,暂存起来 { res.push_back(temp); temp=temp*nums[i]; } ,temp=;i>=;i--)//倒着再乘一遍,刚好错开自己位置的数值 {…
class Solution { public: vector<vector<int>> permute(vector<int>& nums) { int len=nums.size(); vector<vector<int>> res; )//特殊情况 { vector<int> res1; res.push_back(res1); return res; } )//迭代返回条件 { res.push_back(nums);…
4Sum 问题简介:定n个整数和整数目标的数组nums,是否有元素a,b,c,d在nums中,使a+b+c+d=target? 举例: 给定数组 nums = [1, 0, -1, 0, -2, 2], 目标值 target = 0. 结果: [ [-1, 0, 0, 1], [-2, -1, 1, 2], [-2, 0, 0, 2] ] 解法一:先将数组排序,通过三层循环,寻找是否符合四数之和的结果 注: 1.contains方法使用场景 list/Set - contains() Map -…
/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; */ class Solution { public: ListNode *detectCycle(ListNode *head) { if(head==NULL) return NULL; ListNode *fast_no…
class Solution { public: int uniquePaths(int m, int n) { ||n==) ; vector<vector<int>> path;//建立一个二维数组 ;i<m;i++) { vector<int> zeros; ;j<n;j++) zeros.push_back(); path.push_back(zeros); } ;i>=;i--)//从右下角到左上角遍历 { ;j>=;j--) { ||…
class Solution { public: vector<vector<int>> generateMatrix(int n) { )//特殊情况 { vector<vector<int>> empty; return empty; } vector<vector<int>> res; ;i<n;i++)//要先初始化 { vector<int> zeros; ;j<n;j++) zeros.push_b…
1.简介 上一篇讲解了依赖测试的各种方法,今天继续讲解依赖测试的方法,这一篇主要是讲解和分享通过xml文件配置组名依赖方法( 主要是测试组的用法).废话不说,直接上干货. 2.实例 测试组:一个组可包含多个测试方法,可进行组嵌套. 2.1代码设计 1.test1属于功能测试,test2属于接口测试,test3属于接口和功能测试 ,test4是不属于任何组,如下图所示: 2.参考代码 package library; import org.testng.annotations.Test; /**…
这样下去不行啊 ,昨天晚上回来捣鼓了一晚上手机,看个视频还经常开小差,得全力以赴了,不能抱着打酱油的心态了,加油. 今天和yj聊了聊,好多事啊,不能一心工作了,还得考虑结婚,也是醉了. 努力吧,先把考试过了再说.…
前两篇内容为栈和队列的顺序结构的实现,栈和队列都是特殊的线性表,线性表除了有顺序结构以外,还有线性结构. 一.线性表的链形结构--链表 使用顺序存储结构好处为实现方式使用数组方式,顺序是固定的.所以查询某个位置的元素特别容易,时间复杂度为O(1),但是当增加或者删除时,会需要将操作元素后面的元素整体向左或者向右平移.时间复杂度为O(n).所以当线性表查询操作多于增删操作,优先使用顺序存储结构的线性表:当线性表增删操作多于查询操作,则优先使用链式存储结构的线性表. 线性表的链式存储结构的特点是用一…
题目: 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 defined as a character sequence consists of non-space…
作为一门面向对象的编程语言,Java认为一切皆是对象,每个对象都能归属于某个类,甚至每个类均可提取出一种特殊的类型,即Class类型.早在前面介绍多态的时候,就提到每个类都存在独一无二的基因,通过比较实例的类基因与具体类名的类基因,即可分辨某个实例是否属于目标类.例如,若想获取公鸡类的类型,则可通过“类名.class”得到该类的Class对象,详细的获取代码如下所示: // 第一种方式:通过“类名.class”获取 Class clsFromClass = Cock.class; System.…
class Solution { public: int quick_sort_version(vector<int>& nums, int k,int begin,int end,int len) { ) return nums[begin];//这里有点小意外,本来写的是nums[0],这是不对的,比如案例[1,2],k=1 int res_beg=begin,res_end=end;//快排 bool flag=true; while(res_beg!=res_end) { if…
class LRUCache { private: unordered_map<int, list<pair<int,int>>::iterator> _m; // 新节点或刚访问的节点插入表头,因为表头指针可以通过 begin 很方便的获取到. list<pair<int,int>> _list; int _cap; public: LRUCache(int capacity) : _cap(capacity) {} // O(1) // ha…
核心思想是从已知的最短路径推算未知的最短路径. 添加程序: #ifndef GRAPH_H #define GRAPH_H #include "Object.h" #include "SharedPointer.h" #include "Array.h" #include "DynamicArray.h" #include "LinkQueue.h" #include "LinkStack.h&q…
class Solution { public: vector<int> spiralOrder(vector<vector<int>>& matrix) { vector<int> res; int len1=matrix.size();//如果是[[]]边界条件,len1=1,len2=0的,后面虽然边界没有反映,但是依然会返回空数组 ) return res; ].size();//但如果[]边界条件,len1=0,len2那句话就卡死了,所以…
// 面试题68:树中两个结点的最低公共祖先 // 题目:输入两个树结点,求它们的最低公共祖先. #include <iostream> #include "Tree.h" #include <list> using namespace std; bool GetNodePath(const TreeNode* pRoot, const TreeNode* pNode, list<const TreeNode*>& path)//找到根节点到…
// 面试题58(二):左旋转字符串 // 题目:字符串的左旋转操作是把字符串前面的若干个字符转移到字符串的尾部. // 请定义一个函数实现字符串左旋转操作的功能.比如输入字符串"abcdefg"和数 // 字2,该函数将返回左旋转2位得到的结果"cdefgab". #include <iostream> #include <string> void Reverse(char *pBegin, char *pEnd); char* LeftR…
// 面试题58(一):翻转单词顺序 // 题目:输入一个英文句子,翻转句子中单词的顺序,但单词内字符的顺序不变. // 为简单起见,标点符号和普通字母一样处理.例如输入字符串"I am a student. ", // 则输出"student. a am I". #include <iostream> void Reverse(char *pBegin, char *pEnd); char* ReverseSentence(char *pData) {…
// 面试题48:最长不含重复字符的子字符串 // 题目:请从字符串中找出一个最长的不包含重复字符的子字符串,计算该最长子 // 字符串的长度.假设字符串中只包含从'a'到'z'的字符. #include <string> #include <iostream> // 方法一:蛮力法 //不想说话 // 方法一:动态规划 int longestSubstringWithoutDuplication_2(const std::string& str) { ;//记录当前长度…
题目链接:http://www.codeforces.com/problemset/problem/509/A题意:f[i][1]=f[1][i]=1,f[i][j]=f[i-1][j]+f[i][j-1],求f[n][n].C++代码: #include <iostream> using namespace std; ][]; int main() { cin >> n; ;i<=n;i++) f[i][] = f[][i] = ; ; i <= n; i ++) ;…
// 面试题38:字符串的排列 // 题目:输入一个字符串,打印出该字符串中字符的所有排列.例如输入字符串abc, // 则打印出由字符a.b.c所能排列出来的所有字符串abc.acb.bac.bca.cab和cba. #include <iostream> void Permutation(char* pStr, char* pBegin); void Permutation(char* pStr) { if (pStr == nullptr) return; Permutation(pSt…
// 面试题28:对称的二叉树 // 题目:请实现一个函数,用来判断一棵二叉树是不是对称的.如果一棵二叉树和 // 它的镜像一样,那么它是对称的. #include <iostream> #include "BinaryTree.h" bool isSymmetrical(BinaryTreeNode* pRoot1, BinaryTreeNode* pRoot2); bool isSymmetrical(BinaryTreeNode* pRoot) { return is…