leetcode
文章平均质量分 72
vodkazc
这个作者很懒,什么都没留下…
展开
-
Evaluate the value of an arithmetic expression in Reverse Polish Notation.
int evalRPN(vector &tokens){stack operand; for(int i = 0;i < tokens.size(); i++) { if(isOperator(tokens[i])) { char op = tokens[i].at(0); int operand2 = operand.top(); operand.pop();原创 2014-08-21 18:23:05 · 713 阅读 · 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?原创 2014-08-31 16:48:25 · 347 阅读 · 0 评论 -
LeetCode:Binary Tree Postorder
题目如下:Given a binary tree, return the postorder traversal of its nodes' values. 1 \ 2 / 3return [3,2,1].Note: Recursive solution is trivial, could you do it iterative原创 2014-08-29 14:45:06 · 337 阅读 · 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}, reorder it t原创 2014-08-30 17:27:54 · 339 阅读 · 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 / 3return [1,2,3].Note: Recursive soluti原创 2014-08-30 16:09:40 · 316 阅读 · 0 评论 -
LeetCode:Single NumberII
int singleNumber(int A[], int n) { int result = 0; int INT_SIZE = sizeof(int)*8; int* count = new int[INT_SIZE]; memset(count,0,INT_SIZE*sizeof(int)); for(int i = 0;i<n;i++) {原创 2014-09-12 10:31:07 · 439 阅读 · 0 评论 -
LeetCode:Gas Station
Gas StationThere 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 t原创 2014-09-12 10:37:58 · 347 阅读 · 0 评论 -
LeetCode:Candy
CandyThere 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原创 2014-09-12 10:34:34 · 338 阅读 · 0 评论 -
LeetCode:Single Number
Single NumberGiven 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 i原创 2014-09-11 15:13:46 · 288 阅读 · 0 评论 -
LeetCode:Word Break II
Word Break IIGiven 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.原创 2014-09-11 09:45:33 · 473 阅读 · 0 评论 -
LeetCode:Word Break
Word BreakGiven 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, givens = "leetcode",原创 2014-09-11 09:33:10 · 440 阅读 · 0 评论 -
LeetCode:Copy List with Random Pointer
Copy List with Random PointerA 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 o原创 2014-09-11 14:49:35 · 312 阅读 · 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) of the key if原创 2014-08-28 14:55:20 · 375 阅读 · 0 评论 -
LeetCode:Insertion Sort List
Sort a linked list using insertion sortListNode *insertionSortList(ListNode *head) { if(!head || !head->next) return head; ListNode* result =head; ListNode* p = head; ListNode* pre =NU原创 2014-08-26 17:05:22 · 367 阅读 · 0 评论 -
LeetCode:reverse words in a string---两种方法实现
方法一:用到了递归思想原创 2014-08-08 12:11:40 · 431 阅读 · 0 评论 -
LeedCode:Sort List
Sort a linked list in O(n log n) time using constant space complexity.一、kuai'su'pai's原创 2014-08-26 16:19:09 · 365 阅读 · 0 评论 -
LeedCode:Max Points on a Line
Max Points on a Line My SubmissionsGiven n points on a 2D plane, find the maximum number of points that lie on the same straight line.原创 2014-08-25 15:03:11 · 331 阅读 · 0 评论 -
LeedCode: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?原创 2014-08-31 17:44:11 · 327 阅读 · 0 评论