上一页 1 2 3 4 5 6 ··· 38 下一页
摘要: 题目: 解答: 1 class Solution { 2 public: 3 4 vector<vector<string>> partition(string s) 5 { 6 vector<string> temp; 7 vector<vector<string>> result; 8 9 ge 阅读全文
posted @ 2020-05-16 12:54 梦醒潇湘 阅读(267) 评论(0) 推荐(0)
摘要: 题目: 解答: 先序遍历进行处理。 1 /** 2 * Definition for a binary tree node. 3 * struct TreeNode { 4 * int val; 5 * TreeNode *left; 6 * TreeNode *right; 7 * TreeNod 阅读全文
posted @ 2020-05-16 12:36 梦醒潇湘 阅读(282) 评论(0) 推荐(0)
摘要: 题目: 无序数组求中位数。 解答: 利用快排的思想 1、先进行一趟快排,使得div左边的值都比arr[div]小,div右边的值都比arr[div]大,但是这个div的位置是不确定的,可能位于中间,也可能偏左或者偏右。 2、计算出mid所在的下标,如果是奇数则是mid=(size+1)/2,如果是偶 阅读全文
posted @ 2020-05-11 11:36 梦醒潇湘 阅读(1229) 评论(0) 推荐(0)
摘要: 题目: 解答: 在无重复字符代码的基础上先对字符串进行排序,这样重复字符必然相邻,然后在回溯过程中加一句判断条件去除重复排列。 1 class Solution 2 { 3 public: 4 vector<string> permutation(string S) 5 { 6 vector<str 阅读全文
posted @ 2020-05-09 23:37 梦醒潇湘 阅读(481) 评论(0) 推荐(0)
摘要: 题目: 解答: 1 class Solution { 2 vector<string>ans; 3 void backtracking(string &s,int start) 4 { 5 if(start==s.size()) 6 { 7 ans.emplace_back(s); 8 } 9 fo 阅读全文
posted @ 2020-05-09 23:31 梦醒潇湘 阅读(354) 评论(0) 推荐(0)
摘要: 题目: 解答: class Solution { public: int convertInteger(int A, int B) { int res = 0; int temp = A ^ B; while (temp!=0) { int lowbit = temp & (-temp); res+ 阅读全文
posted @ 2020-05-09 23:28 梦醒潇湘 阅读(121) 评论(0) 推荐(0)
摘要: 题目: 解答: 通过中序遍历进行比较。 /** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : v 阅读全文
posted @ 2020-05-09 23:21 梦醒潇湘 阅读(178) 评论(0) 推荐(0)
摘要: 题目: 解答: 1 /** 2 * Definition for a binary tree node. 3 * struct TreeNode { 4 * int val; 5 * TreeNode *left; 6 * TreeNode *right; 7 * TreeNode(int x) : 阅读全文
posted @ 2020-05-09 23:17 梦醒潇湘 阅读(167) 评论(0) 推荐(0)
摘要: 题目: 解答: 1 /** 2 * Definition for a binary tree node. 3 * struct TreeNode { 4 * int val; 5 * TreeNode *left; 6 * TreeNode *right; 7 * TreeNode(int x) : 阅读全文
posted @ 2020-05-09 23:14 梦醒潇湘 阅读(271) 评论(0) 推荐(0)
摘要: 题目: 解答: 利用两个栈s1,s2,其中s1存放排序数据,当执行push()时,若s1.top()<val,将所有小于val的元素放入s2,再将val压入s1中,最后将s2中的元素放入s1中,实现s1的排序push。 1 class SortedStack { 2 public: 3 stack< 阅读全文
posted @ 2020-05-09 23:09 梦醒潇湘 阅读(169) 评论(0) 推荐(0)
上一页 1 2 3 4 5 6 ··· 38 下一页