• 博客园logo
  • 会员
  • 周边
  • 新闻
  • 博问
  • 闪存
  • 众包
  • 赞助商
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
 






canexjtuzju

记录
 
 

Powered by 博客园
博客园 | 首页 | 新随笔 | 联系 | 订阅 订阅 | 管理

随笔分类 -  LeetCode

上一页 1 2 3 下一页

 
LeetCode--Populating Next Right Pointers in Each Node II
摘要:同上题:但是这题需要考虑好对当前节点的left和right的next指针如何设置。 1 /** 2 * Definition for binary tree with next pointer. 3 * struct TreeLinkNode { 4 * int val; 5 * Tre... 阅读全文
posted @ 2014-08-22 21:51 canexjtuzju 阅读(141) 评论(0) 推荐(0)
LeetCode--Populating Next Right Pointers in Each Node
摘要:由于题目意思是满二叉树:所以,对当前节点,设置它的左右子节点的next指针即可root->left->next = root->rightroot->right->next = root->next?root->next->left:NULL 1 /** 2 * Definition for bi... 阅读全文
posted @ 2014-08-22 21:12 canexjtuzju 阅读(132) 评论(0) 推荐(0)
LeetCode--Anagrams
摘要:1 /************************************************************************* 2 > File Name: Anagrams.cpp 3 > Author: zhoukang1991 4 > Mai... 阅读全文
posted @ 2014-08-14 11:54 canexjtuzju 阅读(177) 评论(0) 推荐(0)
LeetCode--N-Queens
摘要:dfs:根据行或者列开始,假设根据行,从第1行开始,从第一行的每一列对应的元素开始dfs,直到第n行,输出结果 1 /************************************************************************* 2 > File Name: N-... 阅读全文
posted @ 2014-08-14 11:10 canexjtuzju 阅读(149) 评论(0) 推荐(0)
LeetCode--Gas Station
摘要:1 /************************************************************************* 2 > File Name: GasStation.cpp 3 > Author: zhoukang1991 4 > Mail: zhoukan... 阅读全文
posted @ 2014-08-13 14:46 canexjtuzju 阅读(200) 评论(0) 推荐(0)
LeetCode--Word Search
摘要:dfshttps://github.com/cane1991/BasicAlogrithmSourceCode/blob/master/LeetCode/WordSearch.cpp 1 /*******************************************************... 阅读全文
posted @ 2014-08-13 13:16 canexjtuzju 阅读(207) 评论(0) 推荐(0)
LeetCode--Gray Code
摘要:格雷码的定义第二次写的,参考别人。代码写的很简洁 1 class Solution { 2 public: 3 vector grayCode(int n) { 4 // Start typing your C/C++ solution below 5 // ... 阅读全文
posted @ 2014-08-12 00:01 canexjtuzju 阅读(167) 评论(0) 推荐(0)
LeetCode--Decode Ways
摘要:其实本题和:http://www.geeksforgeeks.org/count-possible-decodings-given-digit-sequence/是类似的。但是这道题需要考虑错误情况。 1 class Solution { 2 public: 3 int numDecodin... 阅读全文
posted @ 2014-08-11 17:16 canexjtuzju 阅读(163) 评论(0) 推荐(0)
LeetCode--Sudoku Solver
摘要:思路:dfs+数独游戏规则。数独游戏规则是:同行同列不能有重复数字;并且每9宫内不能有重复数字 1 class Solution { 2 public: 3 bool isValid(vector > &board, int a, int b) { 4 int i,j; 5 ... 阅读全文
posted @ 2014-08-10 21:33 canexjtuzju 阅读(181) 评论(0) 推荐(0)
LeetCode--Merge Intervals
摘要:简单题:先按左左边排序,然后对输入的区间和当前结果合并 1 /** 2 * Definition for an interval. 3 * struct Interval { 4 * int start; 5 * int end; 6 * Interval() : ... 阅读全文
posted @ 2014-08-09 20:33 canexjtuzju 阅读(176) 评论(0) 推荐(0)
LeetCode--Valid Number
摘要:这道题真心是难度比较大,不是算法难度,是实现难度,各种case都得考虑到。我没有A过,一开始就把.1这种case当做是错误的。导致程序逻辑乱套了。下面是别人的代码: 1 class Solution { 2 public: 3 bool isNumber(const char *s) { 4... 阅读全文
posted @ 2014-08-09 20:13 canexjtuzju 阅读(173) 评论(0) 推荐(0)
LeetCode--Max Points on a Line
摘要:思路:时间复杂度:O(n^2),挨个遍历。暴力搜索。但是有几点要注意:第一,map的斜率是float,所以,为了不损失精度,求斜率先把int-》float,再相除;第二,注意处理为空和为0的情况。为1是返回0还是1,这个和面试官交流,leetcode上面是返回1 1 /** 2 * Definit... 阅读全文
posted @ 2014-08-09 18:42 canexjtuzju 阅读(176) 评论(0) 推荐(0)
LeetCode--Substring with Concatenation of All Words
摘要:通过hash记录L中各个单词出现的次数,由于每个单词仅仅在S的解中出现一次,且单词长度一样,所以还是很好处理的。但是有一个问题需要注意:string的length函数返回的size_t是无符号的。参看代码注释1http://www.cplusplus.com/reference/string/str... 阅读全文
posted @ 2014-08-07 23:21 canexjtuzju 阅读(146) 评论(0) 推荐(0)
LeetCode--Text Justification
摘要:我的思路:循环遍历输入的单词,每次获取一组符合 fullJustify(vector &words, int L) { 2 // Note: The Solution object is instantiated only once. 3 vector res; 4 ... 阅读全文
posted @ 2014-08-07 22:53 canexjtuzju 阅读(186) 评论(0) 推荐(0)
LeetCode--Minimum Window Substring
摘要:这题关键注意:T可能有重复,所以得统计次数,我之前理解错了,后来参考别人代码才知道的。思路就是双指针+字符hash,具体见注释 1 class Solution { 2 public: 3 string minWindow(string S, string T) { 4 ... 阅读全文
posted @ 2014-08-04 10:26 canexjtuzju 阅读(172) 评论(0) 推荐(0)
LeetCode--Combination Sum II
摘要:思路:类似于上一题,但是加了一个index数组记录结果里面已经存放的元素索引,用来判断当前的元素是否和上一个相同并且上一个是否使用过。主要为了解决重复解的问题。 1 class Solution { 2 public: 3 vector >ans; 4 vector > combin... 阅读全文
posted @ 2014-08-03 21:06 canexjtuzju 阅读(156) 评论(0) 推荐(0)
LeetCode--Combination Sum
摘要:题目链接:https://oj.leetcode.com/problems/combination-sum/思路:题目要求合并的答案需要升序排序。所以先排序,然后每次选一个,递归处理。注意:每个元素可以多次,然后不能有重复的答案,所以碰到处理过的元素就不处理了。 1 class Solution {... 阅读全文
posted @ 2014-08-03 16:42 canexjtuzju 阅读(161) 评论(0) 推荐(0)
LeetCode--Longest Palindromic Substring
摘要:有一个比较容易出错的点:反转求最长公共子序列,这是错误的想法 1 class Solution { 2 public: 3 string longestPalindrome(string s) { 4 int n = s.length(); 5 int lon... 阅读全文
posted @ 2014-08-01 13:34 canexjtuzju 阅读(128) 评论(0) 推荐(0)
LeetCode--Palindrome Number
摘要:关键:如何取最高位的数? 1 class Solution { 2 public: 3 bool isPalindrome(int x) { 4 if(x = 10) 9 {10 div = div*10;11 ... 阅读全文
posted @ 2014-08-01 13:07 canexjtuzju 阅读(142) 评论(0) 推荐(0)
LeetCode--Single Number II
摘要:思路:统计每位出现的次数,mod3;对于k同样适用 1 class Solution { 2 public: 3 int singleNumber(int A[], int n) { 4 int a[32] = {0}; 5 int i = 0; 6 ... 阅读全文
posted @ 2014-07-31 11:31 canexjtuzju 阅读(124) 评论(0) 推荐(0)
 

上一页 1 2 3 下一页