摘要:problem Plus One code 注意可能有进位,而且可能有多个进位,另外注意最高位有进位的情况。 参考 1.leetcode; 完
阅读全文
摘要:problem Length of Last Word 只有一个字符的情况; 最后一个word至字符串末尾之间有多个空格的情况; code1 code2 发现while循环好像比for循环要快。。。 题目求解的是最后一个word的长度,所以还要考虑最后一个word之后还有空格的情况。 参考 1.le
阅读全文
摘要:problem MaximumSubarray code 参考 1. https://leetcode.com/problems/maximum-subarray/description/ 完
阅读全文
摘要:problem Count and Say xiangjian Look-and-say sequence https://en.wikipedia.org/wiki/Look-and-say_sequence code class Solution { public: string countAn
阅读全文
摘要:problem Search Insert Position 一种容易想到的是暴力破解法,一种是常用的二分法。 暴力破解法1(不推荐) class Solution { public: int searchInsert(vector<int>& nums, int target) { int ind
阅读全文
摘要:problem Implement strStr code class Solution { public: int strStr(string haystack, string needle) { if(needle.size()==0) return 0; if( (haystack.size(
阅读全文
摘要:problem RemoveElement class Solution { public: int removeElement(vector<int>& nums, int val) { if(nums.size()==0) return 0; int len = 0; for(size_t i=
阅读全文
摘要:problem RemoveDuplicatesfromSortedArray 注意数组为空的情况要首先考虑,并给出返回值; 注意也要同时给出新的数组的数值; 注意数组最后两个元素的处理; class Solution { public: int removeDuplicates(vector<in
阅读全文
摘要:problem MergeTwoSortedLists 一种方法是迭代,一种方法是递归; code /** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode
阅读全文
摘要:problem Valid Parentheses code class Solution { public: bool isValid(string s) { stack<char> paren; for(const auto& c : s) { switch(c) { case '(': cas
阅读全文
摘要:problem Longest Common Prefix 挨个比较每个字符串的元素是否相同,连续对应位置字符都相同,则为共同字符;否则不是。 code 参考 1.Leetcode-problem; 完
阅读全文
摘要:problem Roman to Integer 每个Roman表示一个数字,可以进行一一映射; 左边字符表示的数字小于右边字符时,减去对应的数字,否则加上; 注意左右字符比较时,最后一个字符不能比较,否则下标会越界; 故最后还需要加上最后一个字符string::back函数; 参考 1.leetc
阅读全文
摘要:problem Palindrome Number 回文数字; 什么是回文数字? 要求不能使用字符串; 翻转一半的数字; 如何判断数字到一半啦? 参考 1.leetcode-problem; 完
阅读全文
摘要:problem: Reverse Integer 注意考虑是否越界; INT_MAX INT_MIN 32bits or 64bits 调整策略,先从简单的问题开始;
阅读全文
摘要:回文串 回文串(palindromic string)是指这个字符串无论从左读还是从右读,所读的顺序是一样的;简而言之,回文串是左右对称的。一般求解一个字符串的最长回文子串问题。 problem:Longest Palindromic Substring 参考 1.LongestPalindromi
阅读全文
摘要:problem: Median of Two Sorted Arrays 什么是median(中值)? solution中使用的是递归方法,可以自己推导一下下。。。 还没有完全明白,先记录下来。 参考 1.leetcode-4-MedianofTwoSortedArrays; 完
阅读全文
摘要:problem:Longest Substring Without Repeating Characters to be continue
阅读全文
摘要:problem: Add Two Numbers 需要学习的是单向链表的基础使用;
阅读全文
摘要:flag -everyday do leetcode problems at least one and at most three. problem here 需要学习的是c++的map类型,之前竟然完全不了解; 还有unorder_map类型;
阅读全文