
Java
文章平均质量分 67
Mavs
CSE
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
追美眉23种设计模式Java
设计模式做为程序员的“内功心法”,越来越受到.net 社区的重视,这种变化是很可喜的,Java社区走在了我们的前面,但这种状况 也许有一天会发生改变。 从追MM谈Java的23种设计模式 1、FACTORY—追MM少不了请吃饭了,麦当劳的鸡翅和肯德基的鸡翅都是MM爱吃的东西,虽然口味有所不同,但不管你带MM去麦当劳或肯 德基,只管向服务员说“来四个鸡翅”就行了。麦当劳和转载 2014-07-19 05:08:08 · 1888 阅读 · 0 评论 -
LeetCode 之 string字符串一
1. Length of last word Given a string s consists of upper/lower-case alphabets and empty space characters ' ', return the length of last word in the string. If the last word does not exist,原创 2014-03-04 04:38:42 · 10018 阅读 · 0 评论 -
[LeetCode 222]Count Complete Tree Nodes
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, except possibly the last, is completely fille原创 2015-08-24 12:28:57 · 534 阅读 · 0 评论 -
[LeetCode 208] Implement Trie (Prefix Tree)
Implement a trie with insert, search, and startsWith methods. Note: You may assume that all inputs are consist of lowercase letters a-z. class TrieNode { boolean exist = false; TrieNo原创 2015-08-24 13:09:38 · 1020 阅读 · 0 评论 -
[LeetCode 236] Lowest Common Ancestor of a Binary Tree
Given a binary tree, find the lowest common ancestor (LCA) of two given nodes in the tree. According to the definition of LCA on Wikipedia: “The lowest common ancestor is defined between two node原创 2015-08-25 13:31:55 · 3185 阅读 · 0 评论 -
[LeetCode 242] Valid Anagram
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: You may ass原创 2015-08-25 14:34:07 · 642 阅读 · 0 评论 -
[LeetCode 258] Add Digits
Given a non-negative integer num, repeatedly add all its digits until the result has only one digit. For example: Given num = 38, the process is like: 3 + 8 = 11, 1 + 1 = 2. Since 2 has on原创 2015-08-25 13:18:16 · 8772 阅读 · 2 评论 -
[LeetCode 211] Add and Search word -- Data Structure Design
Design a data structure that supports the following two operations:void addWord(word) bool search(word) search(word) can search a literal word or a regular expression string containing only letter原创 2015-08-25 14:07:58 · 1024 阅读 · 0 评论 -
[LeetCode 168] Excel Sheet Column Title
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 solutio原创 2015-08-25 14:58:32 · 1842 阅读 · 0 评论 -
[LeetCode 227] Basic Calculator II
Implement a basic calculator to evaluate a simple expression string. The expression string contains only non-negative integers, +, -, *, / operators and empty spaces . The integer division should原创 2015-08-27 13:42:57 · 527 阅读 · 0 评论 -
[LeetCode 190]Reverse Bits
Reverse bits of a given 32 bits unsigned integer. For example, given input 43261596 (represented in binary as 00000010100101000001111010011100), return 964176192 (represented in binary as0011100101原创 2015-08-27 14:45:11 · 528 阅读 · 0 评论 -
[LeetCode 224]Basic Calculator
Implement a basic calculator to evaluate a simple expression string. The expression string may contain open ( and closing parentheses ), the plus + or minus sign -, non-negative integers and em原创 2015-08-27 10:47:56 · 643 阅读 · 0 评论 -
[LeetCode155] Min Stack
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.top() -- Get原创 2015-08-13 13:24:53 · 738 阅读 · 0 评论 -
[LeetCode156] Binary Tree Upside Down
Given a binary tree where all the right nodes are either leaf nodes with a sibling (a left node that shares the same parent node) or empty, flip it upside down and turn it into a tree where the origin原创 2015-08-13 13:22:12 · 755 阅读 · 0 评论 -
[LeetCode 171]Excel Sheet Column Number
Related to question Excel Sheet Column Title Given a column title as appear in an Excel sheet, return its corresponding column number. For example: A -> 1 B -> 2 C -> 3 ...原创 2015-08-28 13:19:37 · 448 阅读 · 0 评论 -
[Leetcode 162] Find Peak Element
A peak element is an element that is greater than its neighbors. Given an input array where num[i] ≠ num[i+1], find a peak element and return its index. The array may contain multiple peaks, i原创 2015-08-14 13:19:51 · 478 阅读 · 0 评论 -
[LeetCode164] Maximum Gap
Given an unsorted array, find the maximum difference between the successive elements in its sorted form. Try to solve it in linear time/space. Return 0 if the array contains less than 2 elements原创 2015-08-15 13:33:38 · 1348 阅读 · 0 评论 -
[LeetCode160] 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-08-14 12:31:57 · 403 阅读 · 0 评论 -
[Leetcode165] Compare Version Numbers
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-empty and co原创 2015-08-16 04:50:19 · 471 阅读 · 0 评论 -
[LeetCode 203] Remove Linked List Elements
Remove all elements from a linked list of integers that have value val. Example Given: 1 --> 2 --> 6 --> 3 --> 4 --> 5 --> 6, val = 6 Return: 1 --> 2 --> 3 --> 4 --> 5 Solution: 1. go thr原创 2015-08-18 13:22:53 · 468 阅读 · 0 评论 -
[LeetCode 206] Reverse Linked List
Reverse a singly linked list. solution: 1. Iteration: two pointers go through linked list, reverse two neigbour list node. 2. Recursion public ListNode reverseList(ListNode head) {原创 2015-08-18 13:54:55 · 772 阅读 · 0 评论 -
[LeetCode 234] Palindrome Linked List
Given a singly linked list, determine if it is a palindrome. Follow up: Could you do it in O(n) time and O(1) space? Solution: 1. Reverse later half part 2. two pointer go through list, one fro原创 2015-08-18 14:38:05 · 674 阅读 · 0 评论 -
[Leetcode 264] Ugly Number II
Write a program to find the n-th ugly number. Ugly numbers are positive numbers whose prime factors only include 2, 3, 5. For example, 1, 2, 3, 4, 5, 6, 8, 9, 10, 12 is the sequence of the first原创 2015-09-02 00:23:05 · 2810 阅读 · 0 评论 -
[Leetcode172]Factorial Trailing Zeroes
Given an integer n, return the number of trailing zeroes in n!. Note: Your solution should be in logarithmic time complexity. solution: zero comes from 2*5, and number of 2 is less than 5. So原创 2015-09-02 07:01:25 · 918 阅读 · 1 评论 -
[LeetCode202] Happy Number
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 the squares原创 2015-09-02 12:36:58 · 1899 阅读 · 3 评论 -
[LeetCode179] Largest Number
Given a list of non negative integers, arrange them such that they form the largest number. For example, given [3, 30, 34, 5, 9], the largest formed number is 9534330. Note: The result may be ve原创 2015-09-02 13:24:36 · 1186 阅读 · 1 评论 -
[LeetCode 237] Delete Node in a linked list
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 node with val原创 2015-08-18 14:45:07 · 465 阅读 · 0 评论 -
[LeetCode 229] Majority element II
Given an integer array of size n, find all elements that appear more than ⌊ n/3 ⌋ times. The algorithm should run in linear time and in O(1) space. Solution: At most has two elements in the r原创 2015-09-02 06:45:13 · 1705 阅读 · 0 评论 -
[LeetCode 191] Number of 1 Bits
Write a function that takes an unsigned integer and returns the number of ’1' bits it has (also known as the Hamming weight). For example, the 32-bit integer ’11' has binary representation 000000原创 2015-09-02 12:13:48 · 1485 阅读 · 1 评论 -
[LeetCode 235] Lowest Common Ancestor of a Binary Search Tree
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 defined betw原创 2015-08-19 14:57:17 · 490 阅读 · 0 评论 -
[LeetCode 207] Course Schedule
There are a total of n courses you have to take, labeled from 0 to n - 1. Some courses may have prerequisites, for example to take course 0 you have to first take course 1, which is expressed as原创 2015-09-03 13:47:45 · 1895 阅读 · 0 评论 -
[LeetCode 226] Invert Binary Tree
Invert a binary tree. 4 / \ 2 7 / \ / \ 1 3 6 9 to 4 / \ 7 2 / \ / \ 9 6 3 1 Solution: 1. recursion 2. Iterative+queue public TreeNode invert原创 2015-08-19 14:04:31 · 418 阅读 · 0 评论 -
[LeetCode 153] Majority Element
Given an array of size n, find the majority element. The majority element is the element that appears more than ⌊ n/2 ⌋ times. You may assume that the array is non-empty and the majority element原创 2015-09-02 00:17:09 · 1258 阅读 · 0 评论 -
[Leetcode 263] Ugly Number
Write a program to check whether a given number is an ugly number. Ugly numbers are positive numbers whose prime factors only include 2, 3, 5. For example, 6, 8 are ugly while 14 is not ugly si原创 2015-09-02 00:19:47 · 1213 阅读 · 0 评论 -
[LeetCode206] Course Schedule II
There are a total of n courses you have to take, labeled from 0 to n - 1. Some courses may have prerequisites, for example to take course 0 you have to first take course 1, which is expressed as原创 2015-09-03 15:09:32 · 1504 阅读 · 0 评论 -
[LeetCode 219] Contains Duplicate II
Given an array of integers and an integer k, find out whether there are two distinct indices i and j in the array such that nums[i] = nums[j] and the difference between i and j is at most k. soluti原创 2015-09-10 13:13:22 · 480 阅读 · 0 评论 -
[LeetCode 217] Contains Duplicate
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 element is原创 2015-09-10 13:09:27 · 433 阅读 · 0 评论 -
[LeetCode 220] Contains Duplicate III
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] is at most t and the difference between i and原创 2015-09-10 13:25:49 · 595 阅读 · 0 评论 -
[LeetCode 278] First Bad Version
You are a product manager and currently leading a team to develop a new product. Unfortunately, the latest version of your product fails the quality check. Since each version is developed based on the原创 2015-09-10 13:48:47 · 918 阅读 · 0 评论 -
[LeetCode 198]House Robber
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 adjacent house原创 2015-09-10 14:24:17 · 516 阅读 · 0 评论