- 博客(49)
- 资源 (4)
- 收藏
- 关注
原创 LetCode 40. 组合总和 II
// 这个判断的目的是排除同一层次相同元素的出现。例如:下面例题中有两个1,在第一次递归中不能都出现1,可以的是第一次递归出现1,第二次递归也可以出现一个1 static int x=[](){ std::ios::sync_with_stdio(false); cin.tie(NULL); return 0; }(); class Solution { public: ...
2018-06-30 19:34:07 321
原创 LetCode 39. 组合总和
// 这里我们新加入三个变量,start记录当前递归到的下标,list为一个解,out保存所有已经得到的解,每次调用新的递归函数时,此时的target都要减去当前数组里的数。 static int x=[](){ std::ios::sync_with_stdio(false); cin.tie(NULL); return 0; }(); class Solution {...
2018-06-30 19:33:42 125
原创 LetCode 38. 报数
static int x=[](){ std::ios::sync_with_stdio(false); cin.tie(NULL); return 0; }(); class Solution { public: string countAndSay(int n) { if (n == 1) { return "1"; ...
2018-06-30 19:33:21 124
原创 LetCode 37. 解数独
static int x=[](){ std::ios::sync_with_stdio(false); cin.tie(NULL); return 0; }(); class Solution { public: void solveSudoku(vector<vector<char>>& board) { solv...
2018-06-30 19:32:57 208
原创 LetCode 36. 有效的数独
static int x=[](){ std::ios::sync_with_stdio(false); cin.tie(NULL); return 0; }(); class Solution { public: bool isValidSudoku(vector<vector<char>>& board) { in...
2018-06-30 19:06:03 152
原创 LetCode 35. 搜索插入位置
static int x=[](){ std::ios::sync_with_stdio(false); cin.tie(NULL); return 0; }(); class Solution { public: int searchInsert(vector<int>& nums, int target) { int left...
2018-06-30 19:05:27 92
原创 LetCode 34. 搜索范围
static int x=[](){ std::ios::sync_with_stdio(false); cin.tie(NULL); return 0; }(); class Solution { public: vector<int> searchRange(vector<int>& nums, int target) { ...
2018-06-30 19:05:03 102
原创 LetCode 33. 搜索旋转排序数组
// {3,5,1} 0 // {5,1,2,3,4} 1 // {5,6,7,8,1,2,3,4} 2 // {5,6,7,8,0,1} 0 // {4,5,6,9,1,2,3} 7 // {4,5,6,7,0,1,2} 0 // {1,3} 3 static int x=[](){ std::ios::sync_with_stdio(false); cin.tie...
2018-06-30 19:04:33 133
原创 LetCode 32. 最长有效括号
static int x=[](){ std::ios::sync_with_stdio(false); cin.tie(NULL); return 0; }(); class Solution { public: int longestValidParentheses(string s) { int res = 0, start = 0;//sta...
2018-06-30 19:04:04 234
原创 LetCode 31. 下一个排列
static int x=[](){ std::ios::sync_with_stdio(false); cin.tie(NULL); return 0; }(); class Solution { public: void nextPermutation(vector<int>& nums) { if (nums.size() ...
2018-06-30 19:03:37 179
原创 LetCode 30. 与所有单词相关联的字串
static int x=[](){ std::ios::sync_with_stdio(false); cin.tie(NULL); return 0; }(); class Solution { public: vector<int> findSubstring(string s, vector<string>& words) ...
2018-06-29 11:32:04 372
原创 LetCode 29. 两数相除
static int x=[](){ std::ios::sync_with_stdio(false); cin.tie(NULL); return 0; }(); class Solution { public: int divide(int dividend, int divisor) { if(dividend == INT_MIN &...
2018-06-29 11:31:34 225
原创 LetCode 28. 实现strStr()
static int x=[](){ std::ios::sync_with_stdio(false); cin.tie(NULL); return 0; }(); class Solution { public: vector<int> next; int strStr(string haystack, string needle) { ...
2018-06-29 11:31:13 113
原创 LetCode 27. 移除元素
static int x=[](){ std::ios::sync_with_stdio(false); cin.tie(NULL); return 0; }(); class Solution { public: int removeElement(vector<int>& nums, int val) { int index ...
2018-06-29 11:30:49 155
原创 LetCode 26. 删除排序数组中的重复项
auto _=[](){ios::sync_with_stdio(0);return cin.tie(0);}(); class Solution { public: int removeDuplicates(vector<int>& nums) { if (nums.size() <= 0) return 0; ...
2018-06-29 11:30:20 99
原创 LetCode 25. k个一组翻转链表
static const auto __ = []() { ios::sync_with_stdio(false); cin.tie(nullptr); return nullptr; }(); class Solution { public: ListNode* reverseKGroup(ListNode* head, int k) { // k...
2018-06-29 11:29:42 303
原创 LetCode 24. 两两交换链表中的节点
static int dividend=[](){ std::ios::sync_with_stdio(false); cin.tie(NULL); return 0; }(); /** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *ne...
2018-06-29 11:29:03 129
原创 LetCode 23. 合并K个排序链表
static int __ = [](){ std::ios::sync_with_stdio(false); cin.tie(nullptr); return 0; }(); /** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ...
2018-06-29 11:28:28 121
原创 LetCode 22. 括号生成
static int x=[](){ std::ios::sync_with_stdio(false); cin.tie(NULL); return 0; }(); class Solution { public: vector<string> generateParenthesis(int n) { vector<string...
2018-06-29 11:27:32 149
原创 LetCode 21. 合并两个有序链表
static int x=[](){ std::ios::sync_with_stdio(false); cin.tie(NULL); return 0; }(); /** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ...
2018-06-29 11:26:55 119
原创 LetCode 20. 有效的括号
static int x=[](){ std::ios::sync_with_stdio(false); cin.tie(NULL); return 0; }(); class Solution { public: bool isValid(string s) { if (s.length() == 0) return tr...
2018-06-27 19:16:37 179
原创 LetCode 19. 删除链表的倒数第N个节点
/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; */ static int x=[](){ std::ios::sync_wit...
2018-06-27 19:16:11 91
原创 LetCode 18. 四数之和
static int x=[](){ std::ios::sync_with_stdio(false); cin.tie(NULL); return 0; }(); class Solution { public: vector<vector<int>> fourSum(vector<int>& nums, int ta...
2018-06-27 19:15:07 167
原创 LetCode 17. 电话号码的字母组合
static int x=[](){ std::ios::sync_with_stdio(false); cin.tie(NULL); return 0; }(); const string base[] = { "", "", "abc", "def", "ghi", "jkl", "mno", "pqrs", "
2018-06-27 19:14:45 456
原创 LetCode 16. 最接近的三数之和
static const auto __ = []() { ios::sync_with_stdio(false); cin.tie(nullptr); return nullptr; }(); class Solution { public: int threeSumClosest(vector<int>& nums, int target) { ...
2018-06-27 19:13:51 167
原创 LetCode 15. 三数之和
static const auto ______ = [](){ std::cout.sync_with_stdio(false); cin.tie(0); return 0; }(); class Solution { public: vector<vector<int>> threeSum(vector<int>&...
2018-06-27 19:13:02 96
原创 LetCode 14. 最长公共前缀
static auto _ = [](){std::ios::sync_with_stdio(false);std::cin.tie(NULL);return 0;}(); class Solution { public: string longestCommonPrefix(vector<string>& strs) { int index = 0; ...
2018-06-27 19:12:35 147
原创 LetCode 13. 罗马数字转整数
static auto _ = [](){std::ios::sync_with_stdio(false);std::cin.tie(NULL);return 0;}(); class Solution { public: int romanToInt(string s) { int tagVal[256]; tagVal['I'] = 1; ...
2018-06-27 19:12:10 100
原创 LetCode 12. 整数转罗马数字
auto ASM2N8=[](){ios::sync_with_stdio(false);return cin.tie(nullptr);}(); class Solution { public: string intToRoman(int num) { if(num <= 0) return ""; string ret = "";...
2018-06-27 19:11:48 87
原创 LetCode 11. 盛最多水的容器
static int any = []() { ios::sync_with_stdio(false); cin.tie(NULL); return 0; }(); class Solution { public: int maxArea(vector<int>& height) { int l = 0, r = height....
2018-06-27 19:11:21 82
原创 LetCode 10. 正则表达式匹配
static auto x = [ ] ( ) { std :: ios :: sync_with_stdio ( false ); cin.tie ( NULL ); return 0; }(); class Solution { public: bool isMatch(string s, string p) { int m = s.leng...
2018-06-25 10:04:53 137
原创 LetCode 9. 回文数
static auto x = []() { std::ios::sync_with_stdio(false); std::cin.tie(0); return 0; }(); class Solution { public: bool isPalindrome(int x) { if (x == 0) ...
2018-06-25 10:03:24 87
原创 LetCode 8. 字符串转整数 (atoi)
class Solution { public: int myAtoi(string str) { int len = str.length(); int index = 0; long long num = 0; bool start = false; int sym = 1; while (...
2018-06-25 10:02:51 96
原创 LetCode 7. 反转整数
class Solution { public: int reverse(int x) { long long num = x; int flag = 1; if (num < 0) { flag = -1; num = -num; } long long result = 0; whil...
2018-06-25 10:02:09 98
原创 LetCode 6. Z字形变换
class Solution { public: string convert(string s, int numRows) { if (numRows == 1) return s; string ret; int n = s.size(); int cycleLen = 2 * numRows - 2; ...
2018-06-25 10:01:38 96
原创 LetCode 5. 最长回文子串
class Solution { public: string longestPalindrome(string s) { int len = s.length(); // 预处理字符串 char* src = new char[len * 2 + 1]; src[0] = '#'; int i = 0; ...
2018-06-25 10:00:22 111
原创 LetCode 4. 两个排序数组的中位数
class Solution { public: double findMedianSortedArrays(vector<int>& nums1, vector<int>& nums2) { int len = nums1.size() + nums2.size(); if (len % 2 == 0) ...
2018-06-25 09:59:57 103
原创 LetCode 3. 无重复字符的最长子串
class Solution { public: int lengthOfLongestSubstring(string s) { int letter[127]; int len = s.length(); int max_len = 1; int i = 0; int j = 0; if (...
2018-06-25 09:59:08 93
原创 LetCode 2. 两数相加
/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; */ class Solution { public: ListNode* ad...
2018-06-25 09:58:39 132
原创 LetCode 1.两数之和
class Solution { public: vector<int> twoSum(vector<int>& nums, int target) { vector<int> two; unordered_map<int, int> m; for (int i =...
2018-06-25 09:57:47 132
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人