![](https://img-blog.csdnimg.cn/20201014180756754.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
LeetCode
GaoJieVery6
这个作者很懒,什么都没留下…
展开
-
LeetCode OJ 第5题 Longest Palindromic Substring 动态规划
动态规划即可,注意外层循环变量是字串长度len.class Solution {public: string longestPalindrome(string s) { int n = s.size(); int dp[1005][1005]; memset(dp, 0, sizeof(dp)); int ans = ...原创 2018-08-10 20:28:25 · 197 阅读 · 0 评论 -
LeetCode OJ 第6题 ZigZag Conversion
找规律,需要注意一些细节#include <iostream>#include <cstdio>#include <cstdlib>#include <string>using namespace std; string convert(string s, int numRows) { string str = ""...原创 2018-08-10 22:34:15 · 136 阅读 · 0 评论 -
LeetCode OJ 第一题 Two Sum
用map的时间复杂度为O(nlogn);用hash的事件复杂度为O(n);下面先给出map的方法class Solution {public: vector<int> twoSum(vector<int>& nums, int target) { vector<int> a; map<int,...原创 2018-08-06 18:33:12 · 161 阅读 · 0 评论 -
LeetCode OJ 第二题 Add Two Numbers (链表)
写的有些复杂了,还是太年轻。。。。 str2 += l2->val; l2 = l2->next; } int size = min(str1.size(), str2.size()); if(size == str1.size()) str = str2; els...原创 2018-08-07 20:25:38 · 148 阅读 · 0 评论 -
LeetCode OJ 第3题 Longest Substring Without Repeating Characters
class Solution {public: int lengthOfLongestSubstring(string s) { int mp[500]; memset(mp, -1, sizeof(mp)); int len = 0; int ans = 0; int beg = 0; i...原创 2018-08-08 17:41:45 · 137 阅读 · 0 评论 -
LeetCode 第8题 String to Integer (atoi)
class Solution {public: int myAtoi(string str) { int n = str.size(); int plus = 1; for(int i = 0; i < str.size(); i++){ if(isdigit(str[i])) break; ...原创 2018-08-13 18:06:06 · 133 阅读 · 0 评论 -
leetcode 第23题 (递归)
class Solution {public: ListNode* merge2Lists(ListNode* node1, ListNode* node2){ if(node1 == NULL) return node2; if(node2 == NULL) return node1; if(node1->val > node2->val){ node2-&...原创 2018-08-18 22:46:14 · 277 阅读 · 0 评论 -
leetcode 第11题 Container With Most Water (贪心)
class Solution {public: int maxArea(vector<int>& height) { int i = 0; int j = height.size()-1; int cur = (j-i)*min(height[i], height[j]); while(i < j...原创 2018-08-18 23:32:17 · 203 阅读 · 0 评论