- 博客(238)
- 资源 (2)
- 收藏
- 关注
原创 Valid Anagram
1 题目描述Given two strings s and t, write a function to determine if t is an anagram of s.For example,s = "anagram", t = "nagaram", return true.s = "rat", t = "car", return false.Note:
2015-08-04 16:50:38 389
原创 Lowest Common Ancestor of a Binary Search Tree
1 题目描述Given a binary search tree (BST), find the lowest common ancestor (LCA) of two given nodes in the BST.According to the definition of LCA on Wikipedia: “The lowest common ancestor is de
2015-08-04 16:27:09 349
原创 Delete Node in a Linked List
1 题目描述Write a function to delete a node (except the tail) in a singly linked list, given only access to that node.Supposed the linked list is 1 -> 2 -> 3 -> 4 and you are given the third nod
2015-08-04 15:54:13 324
原创 Palindrome Linked List
1 题目描述Given a singly linked list, determine if it is a palindrome.题目出处:https://leetcode.com/problems/palindrome-linked-list/2 解题思路题目类型为:单链表和双指针题目,这类题目主要是使用两个指针来确定一些关系。题目中还使用了栈进行辅助,用来进行下一
2015-07-12 14:38:37 274
原创 Excel Sheet Column Title
1 题目描述Given a positive integer, return its corresponding column title as appear in an Excel sheet.For example: 1 -> A 2 -> B 3 -> C ... 26 -> Z 27 -> AA 28 -> AB
2015-07-09 21:41:57 333
原创 Rotate Array
1 题目描述Rotate an array of n elements to the right by k steps.For example, with n = 7 and k = 3, the array [1,2,3,4,5,6,7] is rotated to [5,6,7,1,2,3,4].Note:Try to come up as many sol
2015-07-09 20:51:02 274
原创 House Robber
1 题目描述You are a professional robber planning to rob houses along a street. Each house has a certain amount of money stashed, the only constraint stopping you from robbing each of them is that ad
2015-07-09 16:07:34 257
原创 Happy Number
1 题目描述Write an algorithm to determine if a number is "happy".A happy number is a number defined by the following process: Starting with any positive integer, replace the number by the sum of
2015-07-09 09:29:31 258
原创 Invert Binary Tree
1 题目描述Invert a binary tree. 4 / \ 2 7 / \ / \1 3 6 9to 4 / \ 7 2 / \ / \9 6 3 1题目出处:https://leetcode.com/problems/invert-binary-tree/2 解题思
2015-07-08 22:34:36 260
原创 Contains Duplicate II
1 题目描述Given an array of integers and an integer k, find out whether there there are two distinct indices i and j in the array such that nums[i] = nums[j] and the difference between iand j is
2015-07-08 10:49:13 248
原创 Implement Queue using Stacks
1 题目描述Implement the following operations of a queue using stacks.push(x) -- Push element x to the back of queue.pop() -- Removes the element from in front of queue.peek() -- Get the front el
2015-07-07 21:36:37 375
原创 Rectangle Area
1 题目描述Find the total area covered by two rectilinear rectangles in a 2D plane.Each rectangle is defined by its bottom left corner and top right corner as shown in the figure.Assume t
2015-07-07 21:01:01 280
原创 Isomorphic Strings
1 题目描述Given two strings s and t, determine if they are isomorphic.Two strings are isomorphic if the characters in s can be replaced to get t.All occurrences of a character must be replac
2015-07-07 16:55:15 373
原创 Implement Stack using Queues
1 题目描述Implement the following operations of a stack using queues.push(x) -- Push element x onto stack.pop() -- Removes the element on top of the stack.top() -- Get the top element.empty() --
2015-07-07 15:45:11 255
原创 Min Stack
1 题目描述Design a stack that supports push, pop, top, and retrieving the minimum element in constant time.push(x) -- Push element x onto stack.pop() -- Removes the element on top of the stack.t
2015-07-07 10:57:53 285
原创 Summary Ranges
1 题目描述Given a sorted integer array without duplicates, return the summary of its ranges.For example, given [0,1,2,4,5,7], return ["0->2","4->5","7"].题目出处:https://leetcode.com/problems/summ
2015-07-06 20:54:55 261
原创 Compare Version Numbers
1 题目描述Compare two version numbers version1 and version2.If version1 > version2 return 1, if version1 version2 return -1, otherwise return 0.You may assume that the version strings are non-
2015-07-06 19:48:18 247
原创 Power of Two
1 题目描述Given an integer, write a function to determine if it is a power of two.题目出处:https://leetcode.com/problems/power-of-two/2 解题思路采用打表的方式,因为个数不是很多。采用hashset方式,提高查找效率。3 源代码pac
2015-07-06 17:01:13 362
原创 Contains Duplicate
1 题目描述Given an array of integers, find if the array contains any duplicates. Your function should return true if any value appears at least twice in the array, and it should return false if every
2015-07-02 21:57:58 280
原创 Remove Linked List Elements
题目描述Remove all elements from a linked list of integers that have value val.ExampleGiven: 1 --> 2 --> 6 --> 3 --> 4 --> 5 --> 6, val = 6Return: 1 --> 2 --> 3 --> 4 --> 5解题思路1 当为空链表时
2015-05-17 16:13:23 283
原创 Java中switch的判断类型
package com.larry.test;enum Enum{ RED, BLUE}public class Test1 { public static void main(String[] args) { char c = 0; byte b = 0; short s = 0; int i = 0; long l = 0;// switch (Enum.R
2015-05-17 11:59:22 1720
原创 Reverse Linked List
题目描述Reverse a singly linked list.题目出处:https://leetcode.com/problems/reverse-linked-list/解题思路用一个辅助的List,然后逆序代码package com.larry.easy;import java.util.ArrayList;import java.util
2015-05-17 11:23:18 204
原创 Count Primes
题目描述Description:Count the number of prime numbers less than a non-negative number, n题目出处:https://leetcode.com/problems/count-primes/题目分析给定一个正数,找出小于该数的所有质数代码package com.larr
2015-05-16 21:54:16 259
转载 Java基本数据类型
在移动开发中由于移动设备内存的局限性,往往需要考虑使用的数据类型所占用的字节数。下面简单介绍下Java中几种基本数据类型,以加深记忆。在Java中一共有8种基本数据类型,其中有4种整型,2种浮点类型,1种用于表示Unicode编码的字符单元的字符类型和1种用于表示真值的boolean类型。1.整型类型 存储需求 取值范围 备注i
2015-03-25 15:21:31 340
原创 选择排序-简单选择排序
package com.larry.sorting;import java.util.Arrays;public class EasySelectSort { private void easySelectSort(int s[]){ if(s == null) return; for(int i = 0; i < s.length; i++){ int index = i
2015-03-25 10:49:58 258
原创 交换排序-快速排序
package com.larry.sorting;import java.util.Arrays;public class QuickSort { /** * 一趟排序,将一个元素放在最终位置 * @param s数组的某一部分,初始为整个数组 * @param first待排序的初始元素 * @param end待排序的末尾元素 * @return 该元素的最终位
2015-03-25 10:13:21 231
原创 Number of 1 Bits
1 题目描述 Write a function that takes an unsigned integer and returns the number of ’1' bits it has (also known as theHamming weight).For example, the 32-bit integer ’11' has binary representatio
2015-03-23 16:31:26 313
转载 Java内部类详解
Java内部类详解 说起内部类这个词,想必很多人都不陌生,但是又会觉得不熟悉。原因是平时编写代码时可能用到的场景不多,用得最多的是在有事件监听的情况下,并且即使用到也很少去总结内部类的用法。今天我们就来一探究竟。下面是本文的目录大纲: 一.内部类基础 二.深入理解内部类 三.内部类的使用场景和好处 四.常见的与内部类相关的笔试面试题 若有不正之处,请多谅解并欢迎
2015-03-18 16:50:13 334
转载 浅析Java中的final关键字
浅析Java中的final关键字 谈到final关键字,想必很多人都不陌生,在使用匿名内部类的时候可能会经常用到final关键字。另外,Java中的String类就是一个final类,那么今天我们就来了解final这个关键字的用法。下面是本文的目录大纲: 一.final关键字的基本用法 二.深入理解final关键字 若有不正之处,请多多谅解并欢迎指正。 请尊重作者劳动
2015-03-18 16:19:49 288
原创 算法题-两个字符串的最大公共子串
题目:给定一个query和一个text,均由小写字母组成。要求在text中找出以同样顺序连续出现在query中最长连续字母序列的长度。例如,query为“acbac”,text为“acaccbabb”,那么text中的“cba”为最长的连续出现在query中的字符序列,因此,返回结果应该为其长度3。请注意程序效率。解法:http://blog.sina.com.cn/s/blog_630622
2015-03-17 21:32:04 1239
原创 算法题-写一个函数,输入一个二叉树,树中每个节点存放了一个整数值,函数返回这棵树中相差最大的两个节点间的差的绝对值。请注意程序效率。
package com.larry.test;class TreeNode{ int val; TreeNode lChild; TreeNode rChild; public TreeNode(int val){ this.val = val; lChild = null; rChild = null; }}public class Test { static
2015-03-17 18:11:28 547
原创 Java基础-java中的sleep()和wait()的区别
http://www.cnblogs.com/hongten/p/hongten_java_sleep_wait.html
2015-03-17 17:26:45 256
原创 正则表达式
https://msdn.microsoft.com/zh-cn/library/ae5bf541%28v=vs.90%29.aspx
2015-03-17 15:37:29 250
原创 交换排序-冒泡排序
package com.larry.sorting;import java.util.Arrays;/** * 冒泡排序 * @author admin * */public class BubbleSort { private int[] bubbleSort(int s[]){ if(s == null) return null; int sLen = s.leng
2015-03-16 16:16:31 256
原创 插入排序算法-折半插入排序
折半插入排序和直接插入算法的唯一区别就是在向有序数组中比较的次数的减少,而移动的次数相同。package com.larry.sorting;import java.util.Arrays;/** * 折半插入排序 * @author admin * */public class BinaryInsertionSort { /** * 跳出条件是:low > high
2015-03-16 15:31:57 433
原创 插入排序算法-希尔排序
package com.larry.sorting;import java.util.Arrays;/** * 希尔排序(从小到大) * @author admin * */public class HillSort { private int[] hillSort(int array[]){ int n = array.length; if(n == 0 || n =
2015-03-15 20:34:07 228
原创 插入排序算法-直接插入排序
package com.larry.sorting;import java.util.Arrays;/** * 直接插入排序(从小到大) * @author admin * */public class DirectInsertionSort { private int[] directInsertionSort(int array[]){ int aLen = array
2015-03-15 20:32:45 330
原创 JQuery中的HelloWorld
HelloWorld! $(document).ready(function(){ alert("HelloWord!!!"); }) /*//该方法等价于(不用页面加载完成即可调用) $(function(){ alert("HelloWord
2015-01-26 17:30:55 1372
原创 Intersection of Two Linked Lists
题目描述Write a program to find the node at which the intersection of two singly linked lists begins.For example, the following two linked lists: A: a1 → a2 ↘
2015-01-15 17:04:07 341
原创 Factorial Trailing Zeroes
题目描述Given an integer n, return the number of trailing zeroes in n!.Note: Your solution should be in logarithmic time complexity.文章出处:https://oj.leetcode.com/problems/factorial-trailing-zeroes/
2015-01-14 20:50:09 284
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人