随笔分类 - 算法实现
贴出代码
摘要:1.利用荷兰国旗的思路,每次记住最后一个位置,遇到一个不重复的数,放在它后面,代码很简单。Given a sorted array, remove the duplicates in place such that each element appear onlyonceand return the...
阅读全文
摘要:https://oj.leetcode.com/problems/search-for-a-range/就是一个二分查找,没事练练手 1 public class Solution { 2 public int[] searchRange(int[] A, int target) { 3 ...
阅读全文
摘要:这个问题,前面思考过,当时就是用搜索的方法,此处又遇到一次,发现自己理解的太浅了Given s1, s2, s3, find whether s3 is formed by the interleaving of s1 and s2.For example, Given: s1 = "aabcc",...
阅读全文
摘要:1 public class Solution { 2 public void sortColors(int[] A) { 3 int len=A.length; 4 int beg=0; 5 int end=len-1; 6 ...
阅读全文
摘要:1 /** 2 * Definition for binary tree 3 * public class TreeNode { 4 * int val; 5 * TreeNode left; 6 * TreeNode right; 7 * TreeNo...
阅读全文
摘要:https://oj.leetcode.com/problems/powx-n/提交地址 快速幂的使用,可以研究一下 1 public class Solution { 2 public double pow(double x, int n) { 3 4 i...
阅读全文
摘要:Given a sorted linked list, delete all duplicates such that each element appear onlyonce.For example,Given1->1->2, return1->2.Given1->1->2->3->3, retu...
阅读全文
摘要:Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignoring cases.For example,"A man, a plan, a canal: Pana...
阅读全文
摘要:http://www.cnblogs.com/hansongjiang/p/3810825.html上回写了个博客,是关于1块钱,用 1,2,5分等硬币找钱,共有多种,当时是用搜索出所以可能的组合方式找的,当时参考的博客没看懂。也没仔细想。无意中看到http://www.ibm.com/develo...
阅读全文
摘要:前面总结了leecode上,改为成3出现,只有1个出现1次,的是通过记录每个位的个数来实现的如果count%3=1则为1,否则为0,实现起来充分利用了位运算。编程之美上的,没有写过,今天写一下。http://blog.csdn.net/morewindows/article/details/8214...
阅读全文
摘要:秒杀/** * Definition for binary tree * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode(int x) { val = ...
阅读全文
摘要:https://oj.leetcode.com/problems/path-sum//** * Definition for binary tree * public class TreeNode { * int val; * TreeNode left; * TreeNod...
阅读全文
摘要:做完这道题,只能说基本功很重要,数组中套数组就不会用了,过几天吧1做了,看自己到底等没。https://oj.leetcode.com/problems/binary-tree-level-order-traversal-ii/import java.util.*;/** * Definition ...
阅读全文
摘要:题目不难,很快ac,纯粹靠手感。https://oj.leetcode.com/problems/sum-root-to-leaf-numbers/ 1 /** 2 * Definition for binary tree 3 * public class TreeNode { 4 * ...
阅读全文
摘要:http://www.cnblogs.com/hiddenfox/p/3408931.html 说的很细/** * Definition for singly-linked list. * class ListNode { * int val; * ListNode next; * ...
阅读全文
摘要:http://www.acmerblog.com/leetcode-single-number-ii-5394.html acm之家的讲解总是那么到位public class Solution { public int singleNumber(int[] A) { int an...
阅读全文
摘要:逻辑简单,代码难写,基础不劳,leecode写注释不能出现中文,太麻烦,我写了大量注释,链表问题最重要的就是你那个指针式干啥的提交地址https://oj.leetcode.com/problems/insertion-sort-list//** * Definition for singly-li...
阅读全文
摘要:很简单 提交代码 https://oj.leetcode.com/problems/same-tree/iven two binary trees, write a function to check if they are equal or not.Two binary trees are co...
阅读全文
摘要:以前觉得后续遍历最难写,今天看了篇博客http://blog.csdn.net/sgbfblog/article/details/7773103,其实却是我们仔细比较后续遍历和先序遍历,其实后续遍历就是按照 根右左 的方式先序访问然后逆序就是答案了,会先序就会逆序了leecode 的AC代码:pub...
阅读全文
摘要:写完才知道自己学习都是似是而非啊,大家可以也在leecode上提交代码,纯手写,离开eclipse第一种方式:数据结构书上的,使用栈大概思路。1.不断将根节点的左孩子的左孩子直到为空,在这个过程入栈。2.因为栈顶的节点的左孩子为空,所以栈顶的的节点的左子树肯定访问完毕,所以出栈后直接指向右孩子。其实...
阅读全文

浙公网安备 33010602011771号