Skip to content

Commit e03fa38

Browse files
committed
rename cpp
1 parent 59c669a commit e03fa38

File tree

22 files changed

+122
-16
lines changed

22 files changed

+122
-16
lines changed

README.md

+16-16
Original file line numberDiff line numberDiff line change
@@ -19,25 +19,25 @@ LeetCode solution (C++ and Python)
1919
# Leetcode Hot & Top
2020
| Leetcode | Solution | Basic idea |
2121
| --- | --- | --- |
22-
| 001 [Two Sum](https://leetcode-cn.com/problems/two-sum/ ) | [C++](https://github.com/codename1995/leetcodehub/blob/master/cpp/1_Two_Sum/1_Two_Sum.cpp), [Python](https://github.com/codename1995/leetcodehub/blob/master/python/1.two_sum.py) | 1. Hashtable store the index
22+
| 001 [Two Sum](https://leetcode-cn.com/problems/two-sum/ ) | [C++](https://github.com/codename1995/leetcodehub/blob/master/cpp/001_Two_Sum/001_Two_Sum.cpp), [Python](https://github.com/codename1995/leetcodehub/blob/master/python/1.two_sum.py) | 1. Hashtable store the index
2323
| 002 [Add Two Numbers](https://leetcode-cn.com/problems/add-two-numbers/) | [C++](https://github.com/codename1995/leetcodehub/blob/master/cpp/002_Add_Two_Numbers/002_Add_Two_Numbers.cpp) |
24-
| 003 [Longest Substring without Repeating Characters](https://leetcode-cn.com/problems/longest-substring-without-repeating-characters/)| [C++](https://github.com/codename1995/leetcodehub/blob/master/cpp/3_Longest_Substring_Without_Repeating_Characters/3_Longest_Substring_Without_Repeating_Characters.cpp) | HastTable + TwoPointer
25-
005 [Longest Palindromic Substring](https://leetcode-cn.com/problems/longest-palindromic-substring/ ) | [C++](https://github.com/codename1995/leetcodehub/blob/master/cpp/5_Longest_Palindromic_Substring/5_Longest_Palindromic_Substring.cpp) | 1. 中心扩展
26-
010 [Regular Expression Matching](https://leetcode-cn.com/problems/regular-expression-matching/ ) | [C++](https://github.com/codename1995/leetcodehub/blob/master/cpp/10_Regular_Expression_Matching/10_Regular_Expression_Matching.cpp) | 1. 二维布尔型数组,dp[i][j]表示s[i:]与p[j:]匹配
27-
| 019 [Remove Nth Node From End of List](https://leetcode-cn.com/problems/remove-nth-node-from-end-of-list/) | [C++](https://github.com/codename1995/LeetCodeHub/blob/master/cpp/19_Remove_Nth_Node_from_End_of_List/19_Remove_Nth_Node_from_End_of_List.cpp) |
28-
| 021 [Merge Two Sorted Lists](https://leetcode-cn.com/problems/merge-two-sorted-lists/) | [C++](https://github.com/codename1995/LeetCodeHub/blob/master/cpp/21_Merge_Two_Sorted_Lists/21_Merge_Two_Sorted_Lists.cpp) |
24+
| 003 [Longest Substring without Repeating Characters](https://leetcode-cn.com/problems/longest-substring-without-repeating-characters/)| [C++](https://github.com/codename1995/leetcodehub/blob/master/cpp/003_Longest_Substring_Without_Repeating_Characters/003_Longest_Substring_Without_Repeating_Characters.cpp) | HastTable + TwoPointer
25+
005 [Longest Palindromic Substring](https://leetcode-cn.com/problems/longest-palindromic-substring/ ) | [C++](https://github.com/codename1995/leetcodehub/blob/master/cpp/005_Longest_Palindromic_Substring/005_Longest_Palindromic_Substring.cpp) | 1. 中心扩展
26+
010 [Regular Expression Matching](https://leetcode-cn.com/problems/regular-expression-matching/ ) | [C++](https://github.com/codename1995/leetcodehub/blob/master/cpp/010_Regular_Expression_Matching/010_Regular_Expression_Matching.cpp) | 1. 二维布尔型数组,dp[i][j]表示s[i:]与p[j:]匹配
27+
| 019 [Remove Nth Node From End of List](https://leetcode-cn.com/problems/remove-nth-node-from-end-of-list/) | [C++](https://github.com/codename1995/LeetCodeHub/blob/master/cpp/019_Remove_Nth_Node_from_End_of_List/019_Remove_Nth_Node_from_End_of_List.cpp) |
28+
| 021 [Merge Two Sorted Lists](https://leetcode-cn.com/problems/merge-two-sorted-lists/) | [C++](https://github.com/codename1995/LeetCodeHub/blob/master/cpp/021_Merge_Two_Sorted_Lists/021_Merge_Two_Sorted_Lists.cpp) |
2929
| 028 [Implement Strstr](https://leetcode-cn.com/problems/implement-strstr/) | [C++](https://github.com/codename1995/leetcodehub/blob/master/cpp/028_Implement_Strstr/028_Implement_Strstr.cpp) | 1. 基础字符串匹配,O(mn),超时 <br> 2. KMP
30-
034 [Find First and Last Position of Element in Sorted Array](https://leetcode-cn.com/problems/find-first-and-last-position-of-element-in-sorted-array/)| [C++](https://github.com/codename1995/leetcodehub/blob/master/cpp/34_Find_First_And_Last_Position_Of_Element_In_Sorted_Array/34_Find_First_And_Last_Position_Of_Element_In_Sorted_Array.cpp )| 1. 两次二分,分别返回 不大于/大于 target的第一个位置。需要注意两次二分的细节差异和确定返回位置是否在数组范围内。
31-
| 046 [Permutations ](https://leetcode-cn.com/problems/permutations/) (unique number) | [C++](https://github.com/codename1995/leetcodehub/blob/master/cpp/46_Permutations/46_Permutations.cpp) | 1. DFS+标记 |
32-
| 047 [Permutations ii ](https://leetcode-cn.com/problems/permutations-ii/) (maybe duplicate)| [C++](https://github.com/codename1995/leetcodehub/blob/master/cpp/47_Permutations_II/47_Permutations_II.cpp) | 1. DFS+标记+剪枝
33-
| 050 [Pow(x, n)](https://leetcode-cn.com/problems/powx-n/) | [C++](https://github.com/codename1995/LeetCodeHub/blob/master/cpp/50_Pow/50_Pow.cpp) | 1. 注意考虑特殊情况和溢出 |
34-
| 053 [Maximum Subarray](https://leetcode-cn.com/problems/maximum-subarray/) | [C++](https://github.com/codename1995/leetcodehub/blob/master/cpp/53_Maximum_Subarray/53_Maximum_Subarray.cpp)| 1. DP |
35-
| 054 [Spiral Matrix](https://leetcode-cn.com/problems/spiral-matrix/) | [C++](https://github.com/codename1995/LeetCodeHub/blob/master/cpp/54_Spiral_Matrix/54_Spiral_Matrix.cpp) | 1. 死循环依次缩减四个边界(up, right, bottom, left)并添加元素,边界越界退出循环
30+
034 [Find First and Last Position of Element in Sorted Array](https://leetcode-cn.com/problems/find-first-and-last-position-of-element-in-sorted-array/)| [C++](https://github.com/codename1995/leetcodehub/blob/master/cpp/034_Find_First_And_Last_Position_Of_Element_In_Sorted_Array/034_Find_First_And_Last_Position_Of_Element_In_Sorted_Array.cpp )| 1. 两次二分,分别返回 不大于/大于 target的第一个位置。需要注意两次二分的细节差异和确定返回位置是否在数组范围内。
31+
| 046 [Permutations ](https://leetcode-cn.com/problems/permutations/) (unique number) | [C++](https://github.com/codename1995/leetcodehub/blob/master/cpp/046_Permutations/046_Permutations.cpp) | 1. DFS+标记 |
32+
| 047 [Permutations ii ](https://leetcode-cn.com/problems/permutations-ii/) (maybe duplicate)| [C++](https://github.com/codename1995/leetcodehub/blob/master/cpp/047_Permutations_II/047_Permutations_II.cpp) | 1. DFS+标记+剪枝
33+
| 050 [Pow(x, n)](https://leetcode-cn.com/problems/powx-n/) | [C++](https://github.com/codename1995/LeetCodeHub/blob/master/cpp/050_Pow/050_Pow.cpp) | 1. 注意考虑特殊情况和溢出 |
34+
| 053 [Maximum Subarray](https://leetcode-cn.com/problems/maximum-subarray/) | [C++](https://github.com/codename1995/leetcodehub/blob/master/cpp/053_Maximum_Subarray/053_Maximum_Subarray.cpp)| 1. DP |
35+
| 054 [Spiral Matrix](https://leetcode-cn.com/problems/spiral-matrix/) | [C++](https://github.com/codename1995/LeetCodeHub/blob/master/cpp/054_Spiral_Matrix/054_Spiral_Matrix.cpp) | 1. 死循环依次缩减四个边界(up, right, bottom, left)并添加元素,边界越界退出循环
3636
| 062 [Unique Paths](https://leetcode-cn.com/problems/unique-paths/ ) | [Python](https://github.com/codename1995/leetcodehub/blob/master/python/62_Unique_Paths.py) | 1. DP
37-
| 064 [Minimum Path Sum](https://leetcode-cn.com/problems/minimum-path-sum/) | [C++](https://github.com/codename1995/leetcodehub/blob/master/cpp/64_Minimum_Path_Sum/64_Minimum_Path_Sum.cpp) | 1. DP|
38-
070 [Climbing Stairs](https://leetcode-cn.com/problems/climbing-stairs/ ) | [C++](https://github.com/codename1995/leetcodehub/blob/master/cpp/70_Climbing_Stairs/70_Climbing_Stairs.cpp) | 1. DP|
39-
| 079 [Word Search](https://leetcode-cn.com/problems/word-search/) | [C++](https://github.com/codename1995/LeetCodeHub/blob/master/cpp/79_Word_Search/79_Word_Search.cpp) | 1. DFS+Backtracking
40-
091 [Decode Ways](https://leetcode-cn.com/problems/decode-ways/)| [C++](https://github.com/codename1995/leetcodehub/blob/master/cpp/91_Decode_Ways/91_Decode_Ways.cpp) | 1. DP
37+
| 064 [Minimum Path Sum](https://leetcode-cn.com/problems/minimum-path-sum/) | [C++](https://github.com/codename1995/leetcodehub/blob/master/cpp/064_Minimum_Path_Sum/064_Minimum_Path_Sum.cpp) | 1. DP|
38+
070 [Climbing Stairs](https://leetcode-cn.com/problems/climbing-stairs/ ) | [C++](https://github.com/codename1995/leetcodehub/blob/master/cpp/070_Climbing_Stairs/070_Climbing_Stairs.cpp) | 1. DP|
39+
| 079 [Word Search](https://leetcode-cn.com/problems/word-search/) | [C++](https://github.com/codename1995/LeetCodeHub/blob/master/cpp/079_Word_Search/079_Word_Search.cpp) | 1. DFS+Backtracking
40+
091 [Decode Ways](https://leetcode-cn.com/problems/decode-ways/)| [C++](https://github.com/codename1995/leetcodehub/blob/master/cpp/091_Decode_Ways/091_Decode_Ways.cpp) | 1. DP
4141
| 101 [Symmetric Tree](https://leetcode-cn.com/problems/symmetric-tree/) | [C++](https://github.com/codename1995/LeetCodeHub/blob/master/cpp/101_Symmetric_Tree/101_Symmetric_Tree.cpp) | 1. 递归辅助函数`isMirror(root, root)`
4242
| 102 [Binary Tree Level Order Traversal](https://leetcode-cn.com/problems/binary-tree-level-order-traversal/)| [C++](https://github.com/codename1995/LeetCodeHub/blob/master/cpp/102_Binary_Tree_Level_Order_Traversal/102_Binary_Tree_Level_Order_Traversal.cpp)| 1. 配合队列做呗,加两个计数器变量,一个比较队列是否输出了这一层的所有结点,一个用于记录下一层共有多少结点
4343
| 103 [Binary Tree Zigzag Level Order Traversal](https://leetcode-cn.com/problems/binary-tree-zigzag-level-order-traversal/) | [C++](https://github.com/codename1995/LeetCodeHub/blob/master/cpp/103_Binary_Tree_Zigzag_Level_Order_Traversal/103_Binary_Tree_Zigzag_Level_Order_Traversal.cpp) | 1. 同102
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
#include<iostream>
2+
3+
using namespace std;
4+
5+
struct ListNode {
6+
int val;
7+
ListNode* next;
8+
ListNode(int x) : val(x), next(NULL) {}
9+
10+
};
11+
/**
12+
* Definition for singly-linked list.
13+
* struct ListNode {
14+
* int val;
15+
* ListNode *next;
16+
* ListNode(int x) : val(x), next(NULL) {}
17+
* };
18+
*/
19+
class Solution {
20+
public:
21+
ListNode* addTwoNumbers(ListNode* l1, ListNode* l2) {
22+
int carry = 0;
23+
ListNode* head = l1;
24+
ListNode* curr = l1;
25+
while (l1 && l2) {
26+
int v1 = 0, v2 = 0;
27+
if (v1) {
28+
v1 = l1->val;
29+
l1 = l1->next;
30+
}
31+
if (v2) {
32+
v2 = l2->val;
33+
l2 = l2->next;
34+
}
35+
curr->val = (v1 + v2 + carry) % 10;
36+
carry = (v1 + v2 + carry) / 10;
37+
38+
if (l1 && l2) {
39+
curr->next = l1;
40+
curr = curr->next;
41+
}
42+
else if (!l1) {
43+
curr->next = l2;
44+
break;
45+
}
46+
else if (!l2) {
47+
curr->next = l1;
48+
break;
49+
}
50+
}
51+
52+
return head;
53+
}
54+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#include<string>
2+
#include<iostream>
3+
4+
using namespace std;
5+
6+
class Solution {
7+
public:
8+
int strStr(string haystack, string needle) {
9+
// 2. KMP
10+
11+
12+
// 1. 基础字符串匹配,O(mn),超时
13+
if (needle.size() == 0) return 0;
14+
bool flag = true;
15+
for (int i = 0; i < haystack.size(); ++i) {
16+
flag = true;
17+
int j = 0;
18+
for (; j < needle.size(); ++j) {
19+
if ((i + j) < haystack.size() && needle[j] != haystack[i + j]) {
20+
flag = false;
21+
break;
22+
}
23+
}
24+
if (i + j <= haystack.size() && flag) return i;
25+
flag = false;
26+
}
27+
return -1;
28+
}
29+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#include <string>
2+
#include <iostream>
3+
#include <vector>
4+
#include <iterator>
5+
#include <algorithm>
6+
#include <stack>
7+
#include <random>
8+
#include <numeric>
9+
#include <iomanip>
10+
#include <map>
11+
#include <cmath>
12+
#include <cstring>
13+
14+
using namespace std;
15+
16+
const int negative_inf = INT_MIN + 10;
17+
18+
class Solution {
19+
public:
20+
int maxProfit(int k, vector<int>& prices) {
21+
22+
}
23+
};
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)