02 2014 档案
摘要:题目: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 labele...
阅读全文
摘要:题目: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 co...
阅读全文
摘要:题目: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 ...
阅读全文
摘要:题目:Given an array of integers, every element appears three times except for one. Find that single one.Note: Your algorithm should have a linear runtim...
阅读全文
摘要:题目:Given an array of integers, every element appears twice except for one. Find that single one.Note: Your algorithm should have a linear runtime comp...
阅读全文
摘要:题目: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 co...
阅读全文
摘要:题目: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...
阅读全文
摘要:题目: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.Fo...
阅读全文
摘要:题目:Given a linked list, determine if it has a cycle in it.Follow up: Can you solve it without using extra space?解题思路:判断链表有无环,可用快慢指针进行,快指针每次走两步,慢指针每次走一...
阅读全文
摘要:题目: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 spac...
阅读全文
摘要:题目: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.F...
阅读全文
摘要:题目:Given a binary tree, return the preorder traversal of its nodes' values.For example: Given binary tree {1,#,2,3}, 1 \ 2 / 3return [1,...
阅读全文
摘要:题目:Given a binary tree, return the postorder traversal of its nodes' values.For example: Given binary tree {1,#,2,3}, 1 \ 2 / 3return [3...
阅读全文
摘要:题目:Design and implement a data structure for Least Recently Used (LRU) cache. It should support the following operations: get and set.get(key) - Get t...
阅读全文
摘要:题目:Sort a linked list using insertion sort.解题思路:按题目要求,直接进行插入排序实现代码:#include using namespace std;/*Sort a linked list using insertion sort. */struct Li...
阅读全文
摘要:题目:Sort a linked list in O(n log n) time using constant space complexity.解题思路:根据题目要求,可知只能用归并排序,其他排序算法要么时间复杂度不满足,要么空间复杂度不满足实现代码:#include using namespac...
阅读全文
摘要:题目:Evaluate the value of an arithmetic expression in Reverse Polish Notation.Valid operators are +, -, *, /. Each operand may be an integer or another...
阅读全文
摘要:题目:Given an input string, reverse the string word by word.For example, Given s = "the sky is blue", return "blue is sky the".Clarification:What c...
阅读全文
摘要:题目:Given n points on a 2D plane, find the maximum number of points that lie on the same straight line.解题思路:1,在所有点中选定一个点作为中心点,然后再求剩下的点到该中心点的斜率,如果斜率相同的点...
阅读全文