![](https://img-blog.csdnimg.cn/20201014180756780.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
Java
文章平均质量分 61
MatthrewX
这个作者很懒,什么都没留下…
展开
-
Java中的Iterable和Iterator
由于是Java初学者,对于这个概念不是特别明白。今天看了一篇博文对这个问题有了进一步的理解。 博文地址:http://blog.dreasgrech.com/2010/03/javas-iterators-and-iterables.html 前几天在写coursera的AlgorithmsI这门课程的作业的时候不太明白为什么有时候用Iterator有时候用Iterable,下面谈一下转载 2014-03-04 00:41:06 · 1464 阅读 · 0 评论 -
[Leetcode] 8. String to Integer (atoi)
Implement atoi to convert a string to an integer. Hint: Carefully consider all possible input cases. If you want a challenge, please do not see below and ask yourself what are the possible input ca原创 2015-03-12 10:30:43 · 302 阅读 · 0 评论 -
[Leetcode] 9. Palindrome Number
Determine whether an integer is a palindrome. Do this without extra space. public class Solution { public boolean isPalindrome(int x) { if(x < 0) return false; if(x / 10 == 0) ret原创 2015-03-12 10:40:03 · 305 阅读 · 0 评论 -
[Leetcode] 10. Regular Expression Matching
Implement regular expression matching with support for '.' and '*'. '.' Matches any single character. '*' Matches zero or more of the preceding element. The matching should cover the entire input st原创 2015-03-12 10:53:28 · 326 阅读 · 0 评论 -
[Leetcode] 16. 3Sum Closest
Given an array S of n integers, find three integers in S such that the sum is closest to a given number, target. Return the sum of the three integers. You may assume that each input would have exact原创 2015-03-12 22:05:56 · 368 阅读 · 0 评论 -
[Leetcode] 12. Integer to Roman
Given an integer, convert it to a roman numeral. Input is guaranteed to be within the range from 1 to 3999. 这道题的关键点还是在于能把罗马数字背出来,用贪心算法做。 public class Solution { public String intToRoman(i原创 2015-03-12 21:10:11 · 382 阅读 · 0 评论 -
[Leetcode] 15. 3Sum
Given an array S of n integers, are there elements a, b, c in S such that a + b + c = 0? Find all unique triplets in the array which gives the sum of zero. Note: Elements in a triplet (a,b,c原创 2015-03-12 22:00:07 · 334 阅读 · 0 评论 -
[Leetcode] 14. Longest Common Prefix
Write a function to find the longest common prefix string amongst an array of strings. public class Solution { public String longestCommonPrefix(String[] strs) { if(strs == null || strs.l原创 2015-03-12 21:37:10 · 371 阅读 · 0 评论 -
[Leetcode] 11. Container With Most Water
Given n non-negative integers a1, a2, ..., an, where each represents a point at coordinate (i, ai). n vertical lines are drawn such that the two endpoints of line i is at (i, ai) and (i, 0). Fin原创 2015-03-12 20:51:38 · 318 阅读 · 0 评论 -
[Leetcode] 13. Roman to Integer
Given a roman numeral, convert it to an integer. Input is guaranteed to be within the range from 1 to 3999. public class Solution { public int romanToInt(String s) { if(s == null ||原创 2015-03-12 21:23:36 · 346 阅读 · 0 评论 -
[Leetcode] 7. Reverse Integer
Reverse digits of an integer. Example1: x = 123, return 321 Example2: x = -123, return -321 这道题最初很简单,但leetcode新增了integer的最大值和最小值作为边界条件,让题目变得tricky了,也就是说,当reverse后的integer比Integer.MAX_VALUE大或者In原创 2015-03-12 09:54:30 · 360 阅读 · 0 评论 -
[Leetcode] 6. ZigZag Conversion
The string "PAYPALISHIRING" is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a fixed font for better legibility) P A H N A P L S I原创 2015-03-12 08:52:24 · 332 阅读 · 0 评论 -
各种树的概念小总结
Binary tree: Empty or node with links to left and right binary trees. Complete tree: Perfectly balanced, except for bottom level. Binary heap: Array representation of a heap-ordered complete b原创 2014-03-06 06:08:11 · 708 阅读 · 0 评论 -
Algorithms assignment5和recursive
这一次作业运用了recursive来写。 有疑问可以看《Algorithms 4th Edition》399页的BST写法来加深理解,399页的get,由于方便,加上要递归,本来的get只有要get的参数,没有从哪里开始搜索,所以要加上root,所以分两个get写。 如果两个都是return value,那么直接return。如果像put这样,写的是void,那么就是root=put(原创 2014-03-07 23:42:23 · 1078 阅读 · 0 评论 -
Java出现No enclosing instance of type E is accessible. Must qualify the allocation with an enclosing
最近在看Java,在编译写书上一个例子时,由于书上的代码只有一部分,于是就自己补了一个内部类。结果编译时出现:No enclosing instance of type E is accessible. Must qualify the allocation with an enclosing instance of type E(e.g. x.new A() where x is an i转载 2014-09-02 09:39:21 · 905 阅读 · 0 评论 -
HashMap和Hashtable及HashSet的区别
Hashtable类 Hashtable继承Map接口,实现一个key-value映射的哈希表。任何非空(non-null)的对象都可作为key或者value。 添加数据使用put(key, value),取出数据使用get(key),这两个基本操作的时间开销为常数。 Hashtable通过initial capacity和load factor转载 2014-09-02 10:38:08 · 700 阅读 · 0 评论 -
[Leetcode] 2. Add Two Numbers
You are given two linked lists representing two non-negative numbers. The digits are stored in reverse order and each of their nodes contain a single digit. Add the two numbers and return it as a link原创 2015-03-12 04:12:07 · 344 阅读 · 0 评论 -
[Leetcode] 4. Median of Two Sorted Arrays
There are two sorted arrays A and B of size m and n respectively. Find the median of the two sorted arrays. The overall run time complexity should be O(log (m+n)). 这道题的暂时只会O(m+n)的解法 public class S原创 2015-03-12 06:12:29 · 453 阅读 · 0 评论 -
[Leetcode] 1. Two Sum
最近一直在面试,想把自己做的leetcode的答案都记录下来,方便查询和复习。 Given an array of integers, find two numbers such that they add up to a specific target number. The function twoSum should return indices of the two numbe原创 2015-03-12 04:09:36 · 331 阅读 · 0 评论 -
[Leetcode] 3. Longest Substring Without Repeating Characters
Given a string, find the length of the longest substring without repeating characters. For example, the longest substring without repeating letters for "abcabcbb" is "abc", which the length is 3. Fo原创 2015-03-12 04:55:32 · 357 阅读 · 0 评论 -
[Leetcode] 5. Longest Palindromic Substring
Given a string S, find the longest palindromic substring in S. You may assume that the maximum length of S is 1000, and there exists one unique longest palindromic substring. 从左往右查找,先是查找aba这种的最原创 2015-03-12 07:53:07 · 341 阅读 · 0 评论 -
Java基础知识
之前在面Tripadvisor的时候面了很简单的一道java基础知识,结果没答出来,决定做一些小总结,经常更新更新自己复习看看。 1. String方面 String s = "abc"; String s = new String("abc"); 这两个有什么区别 在java中,用heap和stack存储 The heap stores all objects inc原创 2015-03-23 10:44:27 · 603 阅读 · 0 评论