自定义博客皮肤VIP专享

*博客头图:

格式为PNG、JPG,宽度*高度大于1920*100像素,不超过2MB,主视觉建议放在右侧,请参照线上博客头图

请上传大于1920*100像素的图片!

博客底图:

图片格式为PNG、JPG,不超过1MB,可上下左右平铺至整个背景

栏目图:

图片格式为PNG、JPG,图片宽度*高度为300*38像素,不超过0.5MB

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+
  • 博客(8)
  • 资源 (1)
  • 收藏
  • 关注

原创 [leetcode] House Robber II

和I类似,II变成了环形,即首尾只能取一个。调用两次即可。代码如下: int rob(vector& nums) { if(nums.empty()) return 0; if(nums.size() == 1) return nums[0]; int val = *prev(nums.end());

2015-05-23 18:40:53 322

原创 [leetcode] Add and Search Word - Data structure design

字典树,代码如下: class TrieNode { public: // Initialize your data structure here. TrieNode() { for(int i = 0; i < 26; ++i) next[i] = NULL; end = false; } void ins

2015-05-23 17:46:31 435

原创 [leetcode] Word Search

dfs,代码如下: class Solution { public: bool exist(vector > &board, string word) { const int row = board.size(); const int column = board[0].size(); vector > visited(row, vecto

2015-05-23 17:28:29 364

原创 [leetcode] Word Search II

直接用word search暴力果断超时,根据提示可对words先构建字典树,然后dfs。代码如下: class TrieNode { public: // Initialize your data structure here. TrieNode() { for(int i = 0; i < 26; ++i) next[i] = NULL

2015-05-23 17:27:48 792

原创 [leetcode] Course Schedule II

和Course Schedule类似,记录下结果即可。代码如下: vector findOrder(int numCourses, vector>& prerequisites) { vector result; vector into(numCourses, 0); for(int i = 0; i < prerequisites.size();

2015-05-15 14:41:10 303

原创 [leetcode] Implement Trie (Prefix Tree)

实现字典树基本功能,包括查找key和前缀。代码如下: class TrieNode { public: // Initialize your data structure here. TrieNode() { for(int i = 0; i < 26; ++i) next[i] = NULL; end = false;

2015-05-08 13:59:16 276

原创 [leetcode] Reverse Linked List

链表简单题,遍历头插法即可。代码如下: ListNode* reverseList(ListNode* head) { if(!head) return head; ListNode dummy(-1); dummy.next = head; ListNode *cur = head; Lis

2015-05-07 14:56:48 306

原创 [leetcode] Course Schedule

图算法,判断有向图是否存在回路。拓扑排序即可,代码如下: bool canFinish(int numCourses, vector>& prerequisites) { vector into(numCourses, 0); for(int i = 0; i < prerequisites.size(); ++i) into[prereq

2015-05-07 14:52:21 714

悟透JavaScript

悟透JavaScript是一本学习JavaScript很好的教材

2011-06-04

空空如也

TA创建的收藏夹 TA关注的收藏夹

TA关注的人

提示
确定要删除当前文章?
取消 删除