LeetCode
阿布哥
这个作者很懒,什么都没留下…
展开
-
LeetCode_003:Sort List
package com.abuge;/** * 需求: * 对一个链表进行排序,要求时间复杂度为O(nlogn),空间复杂度为O(1) * @author AbuGe *思路: *1、利用数组存储链表的节点值 *2、通过比较节点的属性值,利用快速排序重新排列节点值 *3、重构链表顺序 * *注:考虑空链表和一个节点的情况,注意空指针异常 *定义数组不能为空。 */cla原创 2014-07-17 15:10:03 · 444 阅读 · 0 评论 -
LeetCode004:BinaryTreePostorderTraversal
package com.abuge;import java.util.ArrayList;import java.util.Iterator;import java.util.List;import org.junit.Test;/** * 有一个二叉树,返回它的后序遍历的值 * 例如: * 二叉树{1,#, 2, 3} * 1 * \ * 2原创 2014-08-01 15:12:08 · 460 阅读 · 0 评论 -
LeetCode006:WordSerarch
package com.abuge;/** * Given a 2D board and a word, find if the word exists in the grid.The word can be constructed from letters of sequentially adjacent cell, where "adjacent" cells are those h原创 2014-08-04 17:14:46 · 540 阅读 · 0 评论 -
LeetCode_002:Evaluate Reverse Polish Notation
package com.abuge;import java.util.Stack;/** * 需求: * 给定一组逆波兰表达式,求其表达式的值 * 思路&步骤: * 1、利用出栈和入栈实现表达式 * 2、对运算符进行判断,将字符串转换成int型,进行运算 * 3、考虑极限情况(只有一个字符串)以及减法和除法的顺序 * @author AbuGe * */public cl原创 2014-07-11 23:44:59 · 427 阅读 · 0 评论 -
LeetCode_001:Reverse Words in a String
package com.abuge;/** * 需求: * 输入一个字符串,将其反转。 * 例: * s = "the sky is blue" * return "blue is sky the" * 方法&步骤: * 1、 将字符串首尾空格去除 * 2、利用正则表达式,将字符串转换成字符串数组 * 3、反转字符串数组 * @author AbuGe * */publ原创 2014-07-10 20:44:41 · 472 阅读 · 0 评论 -
LeetCode005:SingleNumber
package com.abuge;import java.util.Arrays;/** * 需求: * 给定一个整型数组,只有一个元素出现了一次,其它每个元素出现两次,找出这个元素,要求时间复杂度为O(n),不用辅助内存 * @author AbuGe * */public class Solution { public int singleNumber(int[] A原创 2014-08-04 15:28:34 · 452 阅读 · 0 评论 -
LeetCode007:WordLadder
参考:http://www.cnblogs.com/springfor/p/3893499.html题目:Given two words (start and end), and a dictionary, find the length of shortest transformation sequence from start to end, such that:O原创 2014-08-07 16:15:03 · 521 阅读 · 0 评论 -
LeetCode008:Valid Number(正则表达式的运用)
package com.abuge;import org.junit.Test;public class Solution { public boolean isNumber(String s) { String str = s.trim(); if(str.isEmpty()) { return false; } //正则表达式的运用: /*第一原创 2014-08-12 21:48:47 · 941 阅读 · 0 评论