
c++ leetcode
我爱吃火锅
游戏开发者
展开
-
leetcode之Reorder List
题目意思: Given a singly linked list L: L0→L1→…→Ln-1→Ln, eorder 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原创 2014-04-03 22:24:15 · 582 阅读 · 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, given原创 2014-08-07 16:20:27 · 527 阅读 · 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. 意思就是:原创 2014-08-07 16:13:14 · 572 阅读 · 0 评论 -
leetcode之Convert Sorted Array to Binary Search Tree
题目大意: Given an array where elements are sorted in ascending order, convert it to a height balanced BST. 意思就是: 同Convert Sorted List to Binary Search Tree,只是把原创 2014-08-01 11:17:33 · 519 阅读 · 0 评论 -
leetcode之Minimum Depth of Binary Tree
题目大意: Given a binary tree, find its minimum depth. The minimum depth is the number of nodes along the shortest path from the root node down to the nearest leaf node. 意思就是: 给定一棵二叉树,找到它的最短原创 2014-08-01 10:50:37 · 525 阅读 · 0 评论 -
leetcode之Path Sum
题目大意: Path Sum原创 2014-08-01 10:41:05 · 468 阅读 · 0 评论 -
leetcode之Binary Tree Level Order Traversal II
题目大意: Given a binary tree, return the bottom-up level order traversal of its nodes' values. (ie, from left to right, level by level from leaf to root). For example: Given binary tree {3,9,20,#,#,原创 2014-08-01 11:27:28 · 672 阅读 · 0 评论 -
leetcode之Balanced Binary Tree
题目大意: Given a binary tree, determine if it is height-balanced. For this problem, a height-balanced binary tree is defined as a binary tree in which the depth of the two subtrees of every node nev原创 2014-08-01 10:55:44 · 524 阅读 · 0 评论 -
leetcode之Path Sum II
题目大意: Given a binary tree and a sum, find all root-to-leaf paths where each path's sum equals the given sum. For example: Given the below binary tree and sum = 22, 5 /原创 2014-08-01 10:43:51 · 524 阅读 · 0 评论 -
leetcode之Convert Sorted List to Binary Search Tree
题目大意: Given a singly linked list where elements are sorted in ascending order, convert it to a height balanced BST. 意思就是原创 2014-08-01 11:12:12 · 548 阅读 · 0 评论 -
leetcode之Distinct Subsequences
题目大意: Given a string S and a string T, count the number of distinct subsequences of T in S. A subsequence of a string is a new string which is formed from the original string by deleting some (ca原创 2014-07-29 17:33:08 · 623 阅读 · 0 评论 -
leetcode之Flatten Binary Tree to Linked List
题目大意: Given a binary tree, flatten it to a linked list in-place. For example, Given 1 / \ 2 5 / \ \ 3 4 6 The flattened tree should look like: 1原创 2014-07-29 17:36:12 · 488 阅读 · 0 评论 -
leetcode之Populating Next Right Pointers in Each Node
题目大意: Given a binary tree struct TreeLinkNode { TreeLinkNode *left; TreeLinkNode *right; TreeLinkNode *next; } Populate each next pointer to point to its next right nod原创 2014-07-29 17:04:45 · 561 阅读 · 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? 解决思路: 1,首先,如果能用额外的空间,可以把访问过的节点存储到vector中,然后判断是否有重复,如果有原创 2014-04-03 22:34:16 · 664 阅读 · 0 评论 -
leetcode之Reverse Words in a String
题目意思:原创 2014-07-21 11:03:38 · 613 阅读 · 0 评论 -
leetcode之Evaluate Reverse Polish Notation
补充知识——前缀,中缀,后缀表达式的含义以及用计算几如何求前缀和后缀表达式的值。见我的收藏——“前缀、中缀、后缀表达式”。 做题思路: 1,Reverse Polish Notation是后缀表达式 2,根据收藏的文章,该算法用到的主要数据结构是栈。 前缀表达式的计算机求值: 从右至左扫描表达式,遇到数字时,将数字压入堆栈,遇到运算符时,弹出栈顶的两个数,用运算符对它们做相应的计算(原创 2014-03-31 20:48:32 · 659 阅读 · 0 评论 -
leetcode之Max Points on a Line
1,题目意思:在二维平面中,求在一条直线上的点的最大数目 2,做题思路: 两层嵌套循环实现,斜率相同的点即为在一条直线上的点,求得最大点数。 需要注意的是: 1)只有一个点时,直接返回1 ; 没有点时,要返回0,因此需要初始化max_num = 0。 2)最里面的循环分三种情况,第一,两个点相同时。第二,垂直于x轴时,斜率不存在。第三,其他,即普通情况。原创 2014-03-31 22:08:51 · 551 阅读 · 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转载 2014-08-07 17:52:20 · 440 阅读 · 0 评论