第一种方法:迭代 代码语言:javascript 代码运行次数:0 classListNode(object):def__init__(self,x):self.val=x self.next=NoneclassSolution(object):defreverseList(self,head):""":type head:ListNode:rtype:ListNode""" pre=cur=Noneifhead:pre=head cur=head.next pre.next=Noneelse:returnNonewhilecur:...
206. 反转链表,这道题是翻转整个链表 92. 反转链表 II,这道题是翻转链表的一部分 接下来, 用图说明方法:所以,有三步 找中点 翻转中点之后的链表(好多方法, Python和Java 各用一种) 依次拼接 代码: 思路一: class Solution(object): def reorderList(self, head): """ :type head: ListNode :rtype: ...
g++ -std=c++11 -Wall src/bar.cpp -o bar OR You can build all the files usingmake(Use MinGW GCC and GNU Make on Windows). The☢means that you need to have a LeetCode Premium Subscription. ProblemSolution 315Count of Smaller Numbers After Self ...
class Solution { public: int assignBikes(vector<vector<int>>& workers, vector<vector<int>>& bikes) { int m = workers.size(), n = bikes.size(), i, j; vector<vector<int>> dis(m, vector<int>(n)); for(i = 0; i < m; ++i) for(j = 0; j < n; ++j) dis[i][j] = ...
#TitleSolutionDifficulty 1 Search in a big sorted array Java Medium 2 Search Range in Binary Search Tree Java MediumAbout LeetCode Problems' Solutions Resources Readme Activity Stars 0 stars Watchers 2 watching Forks 4.9k forks Report repository Releases No releases published Packages No...
206. 反转链表 class Solution(object): def reverseList(self, head): """ :type head: Optional[ListNode] :rtype: Optional[ListNode] """ pre = None while head: cur = head.next head.next = pre pre = head head = cur return pre 239. 滑动窗口最大值 class Solution(object): def maxSlidi...
218 The Skyline Problem 16.20% Hard 217 Contains Duplicate 35.90% Easy 216 Combination Sum III 27.70% Medium 215 Kth Largest Element in an Array 27.30% Medium 214 Shortest Palindrome 16.80% Hard 213 House Robber II 26.30% Medium 212 Word Search II 15.00% Hard 211 Add and Search Word - Dat...
class Solution { public: int trap(vector<int>& height) { if(height.empty()) return 0; height.push_back(0); int res =0; stack<int> st;//decreasing stack for(int i = 0; i<height.size();++i){ while(!st.empty() && height[i] > height[st.top()]){ ...
2 Add Two Numbers Solution O(max(m,n)) O(1) Medium LinkedList 3 Longest Substring Without Repeating Characters Solution O(n) O(k) Medium HashMap, Sliding Window 4 Median of Two Sorted Arrays Solution ? ? Hard Divide and Conquer 5 Longest Palindromic Substring Solution O(n^2) O(1) Med...
218 The Skyline Problem Algorithms Hard 217 Contains Duplicate Algorithms Easy 216 Combination Sum III Algorithms Medium 215 Kth Largest Element in an Array Algorithms Medium 214 Shortest Palindrome Algorithms Hard 213 House Robber II Algorithms Medium 212 Word Search II Algorithms Hard 211 Add and Se...