随笔分类 -  leetcode

上一页 1 ··· 15 16 17 18 19

【leetcode】66-PlusOne
摘要:problem Plus One code 注意可能有进位,而且可能有多个进位,另外注意最高位有进位的情况。 参考 1.leetcode; 完 阅读全文

posted @ 2018-11-20 09:23 鹅要长大 阅读(133) 评论(0) 推荐(0) 编辑

【leetcode】58-LengthofLastWord
摘要:problem Length of Last Word 只有一个字符的情况; 最后一个word至字符串末尾之间有多个空格的情况; code1 code2 发现while循环好像比for循环要快。。。 题目求解的是最后一个word的长度,所以还要考虑最后一个word之后还有空格的情况。 参考 1.le 阅读全文

posted @ 2018-11-20 08:53 鹅要长大 阅读(192) 评论(0) 推荐(0) 编辑

【leetcode】53-MaximumSubarray
摘要:problem MaximumSubarray code 参考 1. https://leetcode.com/problems/maximum-subarray/description/ 完 阅读全文

posted @ 2018-11-16 14:06 鹅要长大 阅读(144) 评论(0) 推荐(0) 编辑

【leetcode】38-Count and Say
摘要:problem Count and Say xiangjian Look-and-say sequence https://en.wikipedia.org/wiki/Look-and-say_sequence code class Solution { public: string countAn 阅读全文

posted @ 2018-11-13 20:22 鹅要长大 阅读(136) 评论(0) 推荐(0) 编辑

【leetcode】35-Search Insert Position
摘要:problem Search Insert Position 一种容易想到的是暴力破解法,一种是常用的二分法。 暴力破解法1(不推荐) class Solution { public: int searchInsert(vector<int>& nums, int target) { int ind 阅读全文

posted @ 2018-11-12 16:37 鹅要长大 阅读(235) 评论(0) 推荐(0) 编辑

【leetcode】28-Implement strStr
摘要:problem Implement strStr code class Solution { public: int strStr(string haystack, string needle) { if(needle.size()==0) return 0; if( (haystack.size( 阅读全文

posted @ 2018-11-12 16:09 鹅要长大 阅读(197) 评论(0) 推荐(0) 编辑

【leetcode】27-RemoveElement
摘要: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= 阅读全文

posted @ 2018-11-11 17:48 鹅要长大 阅读(159) 评论(0) 推荐(0) 编辑

【leetcode】26-RemoveDuplicatesfromSortedArray
摘要:problem RemoveDuplicatesfromSortedArray 注意数组为空的情况要首先考虑,并给出返回值; 注意也要同时给出新的数组的数值; 注意数组最后两个元素的处理; class Solution { public: int removeDuplicates(vector<in 阅读全文

posted @ 2018-11-11 17:27 鹅要长大 阅读(142) 评论(0) 推荐(0) 编辑

【leetcode】21-MergeTwoSortedLists
摘要:problem MergeTwoSortedLists 一种方法是迭代,一种方法是递归; code /** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode 阅读全文

posted @ 2018-11-09 12:48 鹅要长大 阅读(258) 评论(0) 推荐(0) 编辑

【leetcode】20-ValidParentheses
摘要:problem Valid Parentheses code class Solution { public: bool isValid(string s) { stack<char> paren; for(const auto& c : s) { switch(c) { case '(': cas 阅读全文

posted @ 2018-11-08 17:27 鹅要长大 阅读(193) 评论(0) 推荐(0) 编辑

【leetcode】14-LongestCommonPrefix
摘要:problem Longest Common Prefix 挨个比较每个字符串的元素是否相同,连续对应位置字符都相同,则为共同字符;否则不是。 code 参考 1.Leetcode-problem; 完 阅读全文

posted @ 2018-11-02 08:45 鹅要长大 阅读(164) 评论(0) 推荐(0) 编辑

【leetcode】13-Roman2Integer
摘要:problem Roman to Integer 每个Roman表示一个数字,可以进行一一映射; 左边字符表示的数字小于右边字符时,减去对应的数字,否则加上; 注意左右字符比较时,最后一个字符不能比较,否则下标会越界; 故最后还需要加上最后一个字符string::back函数; 参考 1.leetc 阅读全文

posted @ 2018-11-01 13:25 鹅要长大 阅读(129) 评论(0) 推荐(0) 编辑

【leetcode】9-PalindromeNumber
摘要:problem Palindrome Number 回文数字; 什么是回文数字? 要求不能使用字符串; 翻转一半的数字; 如何判断数字到一半啦? 参考 1.leetcode-problem; 完 阅读全文

posted @ 2018-11-01 09:29 鹅要长大 阅读(262) 评论(0) 推荐(0) 编辑

【leetcode】7-ReverseInteger
摘要:problem: Reverse Integer 注意考虑是否越界; INT_MAX INT_MIN 32bits or 64bits 调整策略,先从简单的问题开始; 阅读全文

posted @ 2018-10-30 20:34 鹅要长大 阅读(162) 评论(0) 推荐(0) 编辑

【letcode】5-LongestPalindromicSubstring
摘要:回文串 回文串(palindromic string)是指这个字符串无论从左读还是从右读,所读的顺序是一样的;简而言之,回文串是左右对称的。一般求解一个字符串的最长回文子串问题。 problem:Longest Palindromic Substring 参考 1.LongestPalindromi 阅读全文

posted @ 2018-10-25 09:02 鹅要长大 阅读(116) 评论(0) 推荐(0) 编辑

【leetcode】4-Median of Two Sorted Arrays
摘要:problem: Median of Two Sorted Arrays 什么是median(中值)? solution中使用的是递归方法,可以自己推导一下下。。。 还没有完全明白,先记录下来。 参考 1.leetcode-4-MedianofTwoSortedArrays; 完 阅读全文

posted @ 2018-10-24 09:11 鹅要长大 阅读(125) 评论(0) 推荐(0) 编辑

leetcode-3-LongestSubstringWithoutRepeatingCharacters
摘要:problem:Longest Substring Without Repeating Characters to be continue 阅读全文

posted @ 2018-10-23 09:16 鹅要长大 阅读(116) 评论(0) 推荐(0) 编辑

【leetcode】2-AddTwoNums
摘要:problem: Add Two Numbers 需要学习的是单向链表的基础使用; 阅读全文

posted @ 2018-10-19 09:15 鹅要长大 阅读(190) 评论(0) 推荐(0) 编辑

leetcode-1-TwoNums
摘要:flag -everyday do leetcode problems at least one and at most three. problem here 需要学习的是c++的map类型,之前竟然完全不了解; 还有unorder_map类型; 阅读全文

posted @ 2018-10-17 09:41 鹅要长大 阅读(148) 评论(0) 推荐(0) 编辑

上一页 1 ··· 15 16 17 18 19

导航

< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

统计

点击右上角即可分享
微信分享提示