摘要: 给定一个包含红,白,蓝且长度为n的数组,将数组元素进行分类使相同颜色的元素相邻,并按照红、白、蓝的顺序进行排序。我们可以使用整数0,1和2分别代表红,白,蓝。解题思路:Java for LeetCode 075 Sort Colorspublic void sortColors(int[] nums... 阅读全文
posted @ 2015-06-15 21:42 TonyLuis 阅读(263) 评论(0) 推荐(0) 编辑
摘要: 用插入排序对链表排序解题思路:最省时间的方法是使用优先级队列,但是无法通过,那就直接插入排序好了。 public ListNode insertionSortList(ListNode head) { ListNode root = new ListNode(Integer.MIN_VALU... 阅读全文
posted @ 2015-06-15 21:39 TonyLuis 阅读(485) 评论(0) 推荐(0) 编辑
摘要: 将一个整数中的数字进行颠倒,当颠倒后的整数溢出时,返回 0 (标记为 32 位整数)。解题思路:JAVA实现如下: public int reverseInteger(int n) { Boolean isNeg = n >= 0 ? false : true; StringBuilder... 阅读全文
posted @ 2015-06-15 21:11 TonyLuis 阅读(348) 评论(0) 推荐(0) 编辑
摘要: 给定一个二叉树,判断它是否是合法的二叉查找树(BST)一棵BST定义为: 节点的左子树中的值要严格小于该节点的值。 节点的右子树中的值要严格大于该节点的值。 左右子树也必须是二叉查找树。解题思路:递归肯定是做不出来的,我的方法比较土,检验中序遍历是否有序,JAVA实现如下: public boole... 阅读全文
posted @ 2015-06-15 20:52 TonyLuis 阅读(502) 评论(0) 推荐(0) 编辑
摘要: Invert a binary tree. 4 / \ 2 7 / \ / \1 3 6 9to 4 / \ 7 2 / \ / \9 6 3 1Trivia:This problem was inspired by thi... 阅读全文
posted @ 2015-06-15 20:18 TonyLuis 阅读(190) 评论(0) 推荐(0) 编辑
摘要: 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()... 阅读全文
posted @ 2015-06-15 20:14 TonyLuis 阅读(230) 评论(0) 推荐(0) 编辑
摘要: Implement a basic calculator to evaluate a simple expression string.The expression string may contain open ( and closing parentheses ), the plus + or ... 阅读全文
posted @ 2015-06-15 20:11 TonyLuis 阅读(647) 评论(0) 推荐(0) 编辑
摘要: 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 sh... 阅读全文
posted @ 2015-06-15 17:41 TonyLuis 阅读(294) 评论(0) 推荐(0) 编辑
摘要: Given a complete binary tree, count the number of nodes.Definition of a complete binary tree from Wikipedia:In a complete binary tree every level, exc... 阅读全文
posted @ 2015-06-15 17:39 TonyLuis 阅读(541) 评论(0) 推荐(0) 编辑
摘要: Given a 2D binary matrix filled with 0's and 1's, find the largest square containing all 1's and return its area.For example, given the following matr... 阅读全文
posted @ 2015-06-15 17:26 TonyLuis 阅读(459) 评论(0) 推荐(0) 编辑
摘要: Given an array of integers, find out whether there are two distinct indices i and j in the array such that the difference between nums[i] and nums[j] ... 阅读全文
posted @ 2015-06-15 16:56 TonyLuis 阅读(260) 评论(0) 推荐(0) 编辑