lzl124631x / leetcode Goto Github PK
View Code? Open in Web Editor NEWMy C++ Code for LeetCode OJ
My C++ Code for LeetCode OJ
Question 328. Odd Even Linked List has got the problem statement of Question 206. Reverse Linked List. When we click on 328. Odd Even Linked List the problem statement displayed is of question 206. Reverse Linked List. Although the solution given is the correct solution to question 328.
Based on the LCP string comparison algorithm you provided, it should be more clear to use a selection algorithm instead of the sorting on the whole array.
string kthLargestNumber(vector<string>& nums, int k) {
nth_element(nums.begin(), nums.begin() + k - 1, nums.end(), [](auto& a, auto& b) {
// return true if a is lexicographical larger than b.
int N = a.size(), M = b.size();
if (N > M) return true;
if (N < M) return false;
for (int i = 0; i < N; ++i) {
if (a[i] != b[i])
return a[i] > b[i];
}
return false;
});
return nums[k-1];
}
130 DFS Solution has time complexity mentioned as O(MN)
but we are not allocating any memory there.
Could you please share your view on that ?
Sorry, if I am missing something there.
First of all, thanks so much for this repo as a very helpful reference. I have a question regarding one of time/space complexity of the code: https://github.com/lzl124631x/LeetCode/tree/master/leetcode/505.%20The%20Maze%20II
Are you sure the Time is O(mn)? Looks like from the discussion and solution tab the best they can achieve with BFS/DFS is O(mnmax(m,n)). Even with PriorityQueue the best achieved is O(mnlog(m*n)). Reference:
https://leetcode.com/problems/the-maze-ii/solution/
https://leetcode.com/problems/the-maze-ii/discuss/?currentPage=1&orderBy=most_votes&query=
In 673 Solution you have an O(n^2) solution. However in the discussion there are several posts claiming to achieve O(nlogn). What are your thoughts?
Input: 5
Output: True
Input: root = [3,5,1,6,2,0,8,null,null,7,4], target = 5, K = 2
Output: [7,4,1]
Input:
board = [
['o','a','a','n'],
['e','t','a','e'],
['i','h','k','r'],
['i','f','l','v']
]
words = ["oath","pea","eat","rain"]
Input
["CustomStack","push","push","pop","push","push","push","increment","increment","pop","pop","pop","pop"]
[[3],[1],[2],[],[2],[3],[4],[5,100],[2,100],[],[],[],[]]
Input:
[[1,1,0],
[1,1,0],
[0,0,1]]
Input: S = "rabbbit", T = "rabbit"
Output: 3
Explanation:
As shown below, there are 3 ways you can generate "rabbit" from S.
(The caret symbol ^ means the chosen letters)
rabbbit
^^^^ ^^
rabbbit
^^ ^^^^
rabbbit
^^^ ^^^
class Solution {
public:
int search(vector& A, int target) {
int L = 0, R = A.size();
while (L <= R) {
int M = (L + R) / 2;
if (A[M] == target) return M;
if (A[M] < target && A.size() != M + 1) L = M + 1;
else R = M - 1;
}
return -1;
}
};
The context inside problem 872 is for 766
https://github.com/lzl124631x/LeetCode/tree/master/leetcode/872.%20Leaf-Similar%20Trees
Since you already have a script to extract solution answer.bookmark.js
, I think it will be convenient to just extract the solution and paste it in this script.
The original solution is perfect. Seems to be faster if pulling the condition of the negative outside.
double pow(double x, int n) {
return n < 0 ? 1/pow(x, (long)-1*n) : pow(x, (long)n);
}
double __pow(double x, long n) {
if (n == 0) return 1;
if (n == 1) return x;
if (n == 2) return x * x;
if(n % 2)
return __pow(__pow(x, n / 2), 2);
else
return __pow(__pow(x, n / 2), 2) * x;
}
1654 Minimum Jumps to Reach Home Medium Solution
This one gives 404 Page Not Found. I wonder if you have done it and the page got corrupted.
From your repo files, I assume you are not using vscode extensions for leetcode local debug as you write a bunch of scripts helping to automate the process. But I cannot find the html file running those js scripts which I find very useful for scraping leetcode api data. Can you shed some light one your workflow? Thanks.
When doing the binary search, setting R = min(K, n2)
would speed up a little.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.