![](https://img-blog.csdnimg.cn/20201014180756927.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
leetcode
Terminator1937
这个作者很懒,什么都没留下…
展开
-
leetcode53 Maximum Subarray
Given an integer array nums, find the contiguous subarray (containing at least one number) which has the largest sum and return its sum.Example:Input: [-2,1,-3,4,-1,2,1,-5,4],Output: 6Explanation:...原创 2018-12-16 10:21:21 · 153 阅读 · 0 评论 -
leetcode 两数相加(链表)
You are given two non-empty linked lists representing two non-negative integers. The digits are stored in reverse order and each of their nodes contain a single digit. Add the two numbers and return i...原创 2019-03-06 12:13:31 · 323 阅读 · 0 评论 -
leetcode 合并两个有序链表
class Solution {public: ListNode* mergeTwoLists(ListNode* l1, ListNode* l2) { if(!l1 && !l2) return NULL; if(l1 && !l2) return l1; if(!l1 && l2) re...原创 2019-03-05 22:18:14 · 190 阅读 · 0 评论 -
leetcode206. 反转链表
设三个指针p, ppre, pNext,分别指向当前结点,当前节点的前一个节点,当前节点的后一个节点。class Solution {public: ListNode* reverseList(ListNode* head) { if (head == NULL || head->next == NULL) return head; ListNode *p = head; ...原创 2019-03-05 22:16:17 · 187 阅读 · 0 评论 -
leetcode17
class Solution {public:vector letterCombinations(string digits) {vector m = { “”, “”, “abc”, “def”, “ghi”, “jkl”, “mno”, “pqrs”, “tuv”, “wxyz” };vector ret;if (digits.size() == 0) return ret;str...原创 2019-02-20 22:44:52 · 300 阅读 · 0 评论 -
leetcode翻转字符串里的单词
Example 1:Input: “the sky is blue”Output: “blue is sky the”Example 2:Input: " hello world! "Output: “world! hello”Explanation: Your reversed string should not contain leading or trailing space...原创 2019-03-01 22:16:48 · 243 阅读 · 0 评论 -
LeetCode 16.3Sum Closest
思路:class Solution {public: int threeSumClosest(vector<int>& nums, int target) { int minVal = 2147483647; int m = 0, n = 0, r = 0; sort(nums.begin(), nums.end()); for (int i =...原创 2019-02-10 16:24:14 · 184 阅读 · 0 评论 -
leetcode 20
class Solution { public: bool isValid(string s) { stack<char> s1; if (s[0] == ')' || s[0] == ']' || s[0] == '}') return false; size_t i = 0; for(; i < s.size(); ++i) { if(s...原创 2019-02-21 16:43:04 · 185 阅读 · 0 评论 -
leetcode 6.ZigZag Convertion
class Solution {public: string convert(string s, int numRows) { if(numRows > s.size() || s.size() < numRows) return s; int numCols = s.size()/(2*numRows-2)*(numRows-2+1)+(s....原创 2019-02-06 16:59:28 · 173 阅读 · 0 评论 -
leetcode235.(二叉搜索树)最近公共祖先
此题比236简单之处在于可以充分利用二叉搜索树的特性,当p和root的差值和q和root的差值符号相异,说明p q肯定在root的两个不同子树中,最近公共祖先就是root。当p q两个结点值都小于根节点时,递归左子树,反之递归右子树。class Solution {public: TreeNode* lowestCommonAncestor(TreeNode* root, TreeNo...原创 2019-03-04 19:32:09 · 421 阅读 · 0 评论