LeetCode
Jasablanca
这个作者很懒,什么都没留下…
展开
-
LeetCode(876)
通过的代码: typedef struct ListNode LNode; typedef struct ListNode *LNode_Pointer; struct ListNode* middleNode(struct ListNode* head) { LNode_Pointer p,q; p=head; q=head; while(p!=NULL&a...原创 2019-05-13 19:27:43 · 261 阅读 · 0 评论 -
LeetCode(234)
通过的代码: typedef struct ListNode LNode; typedef struct ListNode *LNode_Pointer; bool isPalindrome(struct ListNode* head) { LNode_Pointer p,tail,tail_prior; p=head; tail_prior=head; tail...原创 2019-05-13 17:38:27 · 151 阅读 · 0 评论 -
LeetCode(145):二叉树的后序遍历
非递归: 提交代码: class Solution { public: vector<int> postorderTraversal(TreeNode* root) { vector<int> arr; stack<TreeNode*> s; TreeNode *p=root; ...原创 2019-05-30 19:02:26 · 120 阅读 · 0 评论 -
LeetCode(112):路径总和
提交代码: bool hasPathSum(struct TreeNode* root, int sum) { if(root==NULL)//如果搜到空节点还没出现符合值相等的就return false了。 { return false; } else if(root->left==NULL&&root->right=...原创 2019-05-28 21:37:24 · 129 阅读 · 0 评论 -
LeetCode(94):二叉树的中序遍历
提交代码: class Solution { public: vector<int> arr; vector<int> inorderTraversal(TreeNode* root) { if(root!=NULL) { inorderTraversal(root->left); ...原创 2019-05-28 21:43:38 · 85 阅读 · 0 评论 -
LeetCode(144):二叉树的前序遍历
提交代码: class Solution { public: vector<int> arr; vector<int> preorderTraversal(TreeNode* root) { if(root!=NULL) { arr.push_back(root->val); ...原创 2019-05-29 08:23:30 · 84 阅读 · 0 评论 -
LeetCode(102):二叉树的层次遍历
迭代: 提交代码: class Solution { public: vector<vector<int>> levelOrder(TreeNode* root) { vector<vector<int>> res; //vector<int> temp; if(root=...原创 2019-06-04 10:10:20 · 128 阅读 · 0 评论 -
LeetCode(107):二叉树的层次遍历II
参考https://blog.csdn.net/qq_34941153/article/details/90763902 在102题的基础上反转一下即可。 递归: class Solution { public: vector<vector<int>> levelOrderBottom(TreeNode* root) { vector<...原创 2019-06-04 10:32:44 · 103 阅读 · 0 评论 -
LeetCode(617):合并二叉树
我的shit代码(留着自己看): struct TreeNode* mergeTrees(struct TreeNode* t1, struct TreeNode* t2) { struct TreeNode* t3; if(t1==NULL&&t2==NULL) { t3=NULL; return t3; ...原创 2019-07-03 17:15:17 · 117 阅读 · 0 评论 -
LeetCode(206)
通过代码: /** * Definition for singly-linked list. * struct ListNode { * int val; * struct ListNode *next; * }; */ typedef struct ListNode LNode; typedef struct ListNode *LNode_Pointer; s...原创 2019-05-13 15:01:23 · 90 阅读 · 0 评论 -
LeetCode(203)
题目描述: 通过的代码 struct ListNode* removeElements(struct ListNode* head, int val) { struct ListNode *p,*p_prior; struct ListNode *head_temp=(struct ListNode *)malloc(sizeof(ListNode)); /*新开一个结点...原创 2019-05-13 10:52:16 · 476 阅读 · 0 评论 -
LeetCode(445)
通过代码: typedef struct ListNode LNode; typedef struct ListNode *LNode_Pointer; struct ListNode* addTwoNumbers(struct ListNode* l1, struct ListNode* l2) { int flag=false; LNode_Pointer head1,he...原创 2019-05-14 09:12:52 · 196 阅读 · 0 评论 -
LeetCode(169)
解法一:暴力法 #include <stdio.h> #include <string.h> #include <algorithm> int majorityElement(int* nums, int numsSize) { for(int i=0;i<numsSize;i++) { int target=nums[i]...原创 2019-05-07 17:25:58 · 108 阅读 · 0 评论 -
LeetCode(21)
#include <stdio.h> #include <algorithm> #define n 3 struct ListNode { int value; struct ListNode *next; }; struct ListNode* mergeTwoLists(struct ListNode* l1, struct ListNode* l2...原创 2019-05-07 21:34:29 · 86 阅读 · 0 评论 -
LeetCode(104):二叉树的最大深度
通过的代码: int maxDepth(struct TreeNode* root) { if(root==NULL) { return 0; } else { int l_deep=maxDepth(root->left); int r_deep=maxDepth(root->right); ...原创 2019-05-21 15:11:04 · 94 阅读 · 0 评论 -
LeetCode(101):对称二叉树
提交代码: bool mirror(struct TreeNode* p,struct TreeNode* q) { if(p==NULL&&q==NULL) { return true; } else if(p!=NULL&&q!=NULL) { if(p->val==q->va...原创 2019-05-21 15:27:59 · 83 阅读 · 0 评论 -
LeetCode(2)
错误解法: #include <stdio.h> #include <algorithm> struct ListNode { int val; struct ListNode *next; }; typedef struct ListNode Node; typedef struct ListNode *List_Pointer; struct ...原创 2019-05-12 16:09:35 · 79 阅读 · 0 评论 -
LeetCode(83)
#include <stdio.h> #include <algorithm> struct ListNode { int val; struct ListNode *next; }; typedef struct ListNode LNode; typedef struct ListNode *LNode_Pointer; struct ListNo...原创 2019-05-12 21:29:20 · 180 阅读 · 0 评论 -
LeetCode(237)
出得莫名其名的一道题。我还纠结了半天head。看了题解之后发现这道题是很巧妙的一道题。 void deleteNode(struct ListNode* node) { node->val=node->next->val; node->next=node->next->next; } ...原创 2019-05-12 21:47:21 · 115 阅读 · 0 评论 -
LeetCode(108):将有序数组转换为二叉搜索树
通过代码: class Solution { public: TreeNode* sortedArrayToBST(vector<int>& nums) { if(nums.empty()==true) return 0; return help(nums,0,nums.size()-1);//不是nu...原创 2019-07-03 17:55:11 · 136 阅读 · 0 评论