- 博客(16)
- 收藏
- 关注
原创 142. Linked List Cycle II
题目描述解题思路先找到第一次相遇的地方,再将另一指针置为head,两指针再以相同的速度前进,第一次遇见的地方就是循环链开始的节点位置。证明如下代码如下ListNode *delectCycle(ListNode *head){ if(head == null || head -> next == null){ return null; } ListNode * firstp = h...
2018-06-07 23:21:59
160
原创 133. Clone Graph
题目描述解题思路数据结构:利用了map集合代码如下public class UndirectedGraphNode{ //每个结点之中都包含一个整数和一个数组 //存的都是与之相邻的所有结点 int label; ArrayList<UndirectedGraphNode> neighbors;}public class Solution{ private HashMa...
2018-06-05 09:32:02
148
原创 131. Palindrome Partitioning
题目描述解题思路(从左往右循环,从上往下进行递归)代码如下所示public class Solution{ List<List<String>> resultLst; ArrayList<String> currLst; public List<List<String>> partition(String s){ resultL...
2018-06-04 21:26:29
136
原创 130. Surrounded Regions
题目描述解题思路==先将不要变的O换为1,再将其余的O变成X,最后再将1变回为O代码如下class Solution{public: void solve(vector<vector<char>>& board){ int i,j; //计算二维行数 int row = board.size(); //如果长度为0的话则直接返回 if(!ro...
2018-06-03 20:34:55
1758
原创 129. Sum Root to Leaf Numbers
题目描述解题思路:对于二叉树常用的解题方式是递归的方式public int sumNumbers(TreeNode root){ return sum(root, 0);}public int sum(TreeNode n, int s){ if(n == null){ return 0; } //如果为叶子节点,代表的是递归的出口 if(n.right == null &...
2018-06-03 19:58:09
150
原创 128. Longest Consecutive Sequence
题目描述如下解题思路解题代码如下public int longestConsecutive(int[] num){ int res = 0; HashMap<Integer,Integer> map = new HashMap<Integer,Integer>(); for(int n : num){ //如果map集合中没有包含n if(!map.conta...
2018-06-03 19:41:06
93
原创 126.Word Ladder II
public List<List> findLadders(String start, String end, Set dict){ results = new ArrayList<List>(); if(dict.size() == 0){ return results; } int min = Integer.MAX_VALUE; //队列辅助树的宽度搜索...
2018-06-03 19:14:41
202
原创 125. Valid Palindrome
public class Solution{ public boolean isPalindrome(String s){ if(s.isEmpty()){ return true; } int head = 0, tail = s.length() - 1; char cHead, cTail; while(head <= tail){ cHead = s...
2018-06-02 18:46:36
97
原创 124. Binary Tree Maximum Path Sum
public class Solution{ int maxValue; public int maxPathSum(TreeNode root){ maxValue = Integer.MIN_VALUE; maxPathDown(root); return maxValue; } private int maxPathDown(TreeNode node){ if(n...
2018-06-02 18:33:21
95
原创 123. Best Time to Buy and Sell Stock III
Say you have an array for which the ith element is the price of a given stock on day i.Design an algorithm to find the maximum profit. You may complete at most two transactions.Note: You may not engag...
2018-06-02 18:09:01
166
原创 122. Best Time to Buy and Sell Stock II
Say you have an array for which the ith element is the price of a given stock on day i.Design an algorithm to find the maximum profit. You may complete as many transactions as you like (i.e., buy one ...
2018-06-02 16:11:45
136
原创 爬虫--实战--极课学院课程爬取
#实战环节#目标网站 http://www/jikexueyuan.com/course/#目标内容:课程名称,课程介绍,课程时间,课程等级,学习人数#涉及到的技术有 Request抓取网页 re.sub换页 正则表达式匹配内容#当抓取的内容很多时候要获得内容的时候可以利用标签的class属性#利用先抓大再抓小的技巧import requestsimport re#将命令提示符的...
2018-05-30 12:17:21
495
原创 找出根到叶子结点的距离的最小值
//找出根到叶子结点的距离的最小值public int minDepth(TreeNode root){ if(root == null){ return 0; } int left = minDepth(root.left); int right = minDepth(root.right); if(left == 0 || right == 0) ? left + right ...
2018-05-27 12:06:53
616
原创 找出二叉树中所有和为给定值的路径
//找出二叉树中所有和为给定值的路径,以数组的形式打印出来//采用深搜的方法来实现public List<List<Integer>> pathSum(TreeNode root, int sum){ List<List<Integer>> result = new LinkedList<List<Integer>>()...
2018-05-27 12:00:59
775
原创 把一棵二叉树压平
/*采用后序遍历的方法来实现*/private TreeNode prev = null;public void flatten(TreeNode root){ if(root == null){ return; } flatten(root.right); flatten(root.left); root.right = prev; root.left = null; ...
2018-05-27 11:48:24
244
原创 判断是否为平衡二叉树
//判断给定的二叉树是否是一棵平衡二叉树/* 采用了递归的方式如果是平衡二叉树的话则返回的是树的高度否则返回-1 只要经过判断后有一个值为-1则代表不是平衡二叉树,最终的结果返回为false*/public boolean isBalanced(TreeNode root){ if(root == null){ return true; } return height(root...
2018-05-27 11:44:13
180
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人