随笔分类 - LeetCode
摘要:1 #include "000库函数.h" 2 3 4 //自解1: 5 class Solution { 6 public: 7 int removeElement(vector& nums, int val) { 8 if (nums.size() == 0)return 0; 9 int j = 0; 10 fo...
阅读全文
摘要:1 #include "000库函数.h" 2 3 ////////////自解1:逐个筛选在赋值,时间最短36ms 4 class Solution { 5 public: 6 int removeDuplicates(vector& nums) { 7 if (nums.size() v; 9 v.push_back(nums[0])...
阅读全文
摘要:1 #include "000库函数.h" 2 3 4 5 struct ListNode { 6 int val; 7 ListNode *next; 8 ListNode(int x) : val(x), next(NULL) {} 9 }; 10 /************************自己解答*********...
阅读全文
摘要:1 #include "000库函数.h" 2 3 4 5 6 struct ListNode { 7 int val; 8 ListNode *next; 9 ListNode(int x) : val(x), next(NULL) {} 10 }; 11 //注意,该链表是无头结点,为了不乱,自己加了一个头结点 12 class Soluti...
阅读全文
摘要:1 #include "000库函数.h" 2 3 4 5 struct ListNode { 6 int val; 7 ListNode *next; 8 ListNode(int x) : val(x), next(NULL) {} 9 }; 10 //自己解法,比较笨,为用算法,即将所有元素合并再排序 11 ListNo...
阅读全文
摘要:1 #include "000库函数.h" 2 3 4 5 6 //使用回溯法,当左括号数量大于右括号数量,则可以放置右括号 7 void recall(vector&bracket, string s, int left, int right) {//bracket使用引用,确保其变化会被保留 8 if (left > right)return; 9 ...
阅读全文
摘要://此题所谓的排序,并不是要把合并后的数字排序,而是将l1,l2的数字合并 struct ListNode { int val; ListNode *next; ListNode(int x) : val(x), next(NULL) {}//构造函数 }; //使用小学生插队思想,多次遍历链表进行排序,不推荐 ListNode* mergeTwoList...
阅读全文
摘要://使用栈的思想,先进后出原则,因为出来的必须是与目前的括号形成一对 bool isValid(string s) { if (s.size() == 0)return true; if (s.size() == 1)return false; stackTemp; for (int i = 0; i < s.size(); ++i) { if (s[i] == '(' || s[...
阅读全文
摘要:1 //使用两次遍历 2 ListNode* removeNthFromEnd(ListNode* head, int n) { 3 if (!head->next) return NULL; 4 int len = 0; 5 ListNode *p = head; 6 while (p) { 7 p = p->next; 8 ...
阅读全文
摘要:1 //使用三数之和中的双指针的思想,固定外围两个数 2 vector> fourSum(vector& nums, int target) { 3 sort(nums.begin(), nums.end()); 4 vector>Res; 5 if (nums.size() = 3;) { 7 for (int a = 0; a targe...
阅读全文