
leetcode_cpp_python
文章平均质量分 62
limwz
这个作者很懒,什么都没留下…
展开
-
leetcode之Min Stack
问题描述如下: Design a stack that supports push, pop, top, and retrieving the minimum element in constant time. push(x) -- Push element x onto stack.pop() -- Removes the element on top of the stack.原创 2014-12-03 15:16:52 · 247 阅读 · 0 评论 -
leetcode之Reorder List
问题描述如下: Given a singly linked list L: L0→L1→…→Ln-1→Ln, reorder it to: L0→Ln→L1→Ln-1→L2→Ln-2→… You must do this in-place without altering the nodes' values. For example, Given {1,2,3,4}, r原创 2014-12-06 10:15:48 · 269 阅读 · 0 评论 -
leetcode之Linked List Cycle II
问题描述如下: Given a linked list, return the node where the cycle begins. If there is no cycle, return null. Follow up: Can you solve it without using extra space? 问题链接 cpp代码如下: class Solution原创 2014-12-06 10:21:42 · 261 阅读 · 0 评论 -
leetcode之Copy List with Random Pointer
问题描述如下: A linked list is given such that each node contains an additional random pointer which could point to any node in the list or null. Return a deep copy of the list. 问题链接 cpp代码如下: cla原创 2014-12-06 14:25:58 · 316 阅读 · 0 评论 -
leetcode之Word Break II
问题描述如下: Given a string s and a dictionary of words dict, add spaces in s to construct a sentence where each word is a valid dictionary word. Return all such possible sentences. For example,原创 2014-12-06 10:43:16 · 359 阅读 · 0 评论 -
leetcode之Word Break
问题描述如下: Given a string s and a dictionary of words dict, determine if s can be segmented into a space-separated sequence of one or more dictionary words. For example, given s = "leetcode", d原创 2014-12-06 10:49:34 · 303 阅读 · 0 评论 -
leetcode之Single Number
Given an array of integers, every element appears twice except for one. Find that single one. Note: Your algorithm should have a linear runtime complexity. Could you implement it without using ext原创 2014-12-06 14:41:50 · 328 阅读 · 0 评论 -
leetcode之Gas Station
There are N gas stations along a circular route, where the amount of gas at station i is gas[i]. You have a car with an unlimited gas tank and it costs cost[i] of gas to travel from station i to原创 2014-12-06 15:14:16 · 287 阅读 · 0 评论 -
leetcode之Clone Graph
Clone an undirected graph. Each node in the graph contains a label and a list of its neighbors. OJ's undirected graph serialization: Nodes are labeled uniquely. We use # as a separator for each原创 2014-12-06 15:49:04 · 332 阅读 · 0 评论 -
leetcode之Single Number II
问题描述如下: Given an array of integers, every element appears three times except for one. Find that single one. Note: Your algorithm should have a linear runtime complexity. Could you implement i原创 2014-12-06 14:39:09 · 303 阅读 · 0 评论 -
leetcode之Candy
There are N children standing in a line. Each child is assigned a rating value. You are giving candies to these children subjected to the following requirements: Each child must have at least on原创 2014-12-06 14:57:46 · 343 阅读 · 0 评论 -
leetcode之LRU Cache
问题描述如下: Design and implement a data structure for Least Recently Used (LRU) cache. It should support the following operations: get and set. get(key) - Get the value (will always be positive) o原创 2014-12-06 09:47:36 · 330 阅读 · 0 评论 -
leetcode之Linked List Cycle
问题描述如下: Given a linked list, determine if it has a cycle in it. Follow up: Can you solve it without using extra space? 问题链接 cpp代码如下: class Solution { public: bool hasCycle(ListNode *he原创 2014-12-06 10:25:10 · 288 阅读 · 0 评论 -
leetcode之Intersection of Two Linked Lists
问题描述如下: Write a program to find the node at which the intersection of two singly linked lists begins. For example, the following two linked lists: A: a1 → a2 ↘原创 2014-12-03 14:24:43 · 300 阅读 · 0 评论 -
leetcode之Find Minimum in Rotated Sorted Array II
问题描述如下: Follow up for "Find Minimum in Rotated Sorted Array": What if duplicates are allowed? Would this affect the run-time complexity? How and why? Suppose a sorted array is rotated at原创 2014-12-03 15:43:09 · 274 阅读 · 0 评论 -
leetcode之Find Minimum in Rotated Sorted Array
问题描述如下: Suppose a sorted array is rotated at some pivot unknown to you beforehand. (i.e., 0 1 2 4 5 6 7 might become 4 5 6 7 0 1 2). Find the minimum element. You may assume no duplica原创 2014-12-03 15:48:18 · 247 阅读 · 0 评论 -
leetcode之Max Points on a Line
问题描述如下: Given n points on a 2D plane, find the maximum number of points that lie on the same straight line. 问题链接 cpp代码如下: class Solution { public: int maxPoints(vector &points) { i原创 2014-12-04 15:22:21 · 287 阅读 · 0 评论 -
leetcode之Reverse Words in a String
问题描述如下: Given an input string, reverse the string word by word. For example, Given s = "the sky is blue", return "blue is sky the". click to show clarification. Clarification: Wha原创 2014-12-04 13:58:57 · 299 阅读 · 0 评论 -
leetcode之Evaluate Reverse Polish Notation
问题描述如下: Evaluate the value of an arithmetic expression in Reverse Polish Notation. Valid operators are +, -, *, /. Each operand may be an integer or another expression. Some examples:原创 2014-12-04 14:14:56 · 268 阅读 · 0 评论 -
leetcode之Sort List
问题描述如下: Sort a linked list in O(n log n) time using constant space complexity. 问题链接 问题链接 问题链接 问题链接 问题链接 问题链接 问题链接 问题链接 问题链接 问题链接 问题链接 问题链接 问题链接 cpp代码如下: class Solution { public: ListNode原创 2014-12-05 09:33:36 · 309 阅读 · 0 评论 -
leetcode之Insertion Sort List
问题描述如下: Sort a linked list using insertion sort. 问题链接 cpp代码如下: class Solution { public: ListNode *insertionSortList(ListNode *head) { if(head==NULL||head->next==NULL)return head;原创 2014-12-05 09:52:14 · 236 阅读 · 0 评论 -
leetcode之Binary Tree Postorder Traversal
问题描述如下: Given a binary tree, return the postorder traversal of its nodes' values. For example: Given binary tree {1,#,2,3}, 1 \ 2 / 3 return [3,2,1]. Note: Re原创 2014-12-06 09:55:41 · 270 阅读 · 0 评论 -
leetcode之Binary Tree Preorder Traversal
问题描述如下: Given a binary tree, return the preorder traversal of its nodes' values. For example: Given binary tree {1,#,2,3}, 1 \ 2 / 3 return [1,2,3]. Note: Rec原创 2014-12-06 10:01:11 · 243 阅读 · 0 评论