- 博客(86)
- 资源 (1)
- 收藏
- 关注
原创 670. Maximum Swap
需要注意的关键是相同的数字的处理class Solution { public int maximumSwap(int num) { char[]nums = String.valueOf(num).toCharArray(); for (int i = 0; i < nums.length; i++) { char max = num
2017-09-05 14:11:32 393
原创 2. Add Two Numbers
class Solution { public ListNode addTwoNumbers(ListNode l1, ListNode l2) { ListNode preNode = new ListNode(0); ListNode tail = preNode; int pre = 0; while (l1!=null&
2017-09-03 12:12:44 223
原创 20. Valid Parentheses
class Solution { public boolean isValid(String s) { char[]symbols = s.toCharArray(); Stack<Character> stack = new Stack<>(); for (int i = 0; i < symbols.length; i++) {
2017-09-03 09:58:48 241
原创 17. Letter Combinations of a Phone Number
class Solution { public List<String> letterCombinations(String digits) { LinkedList<String> ans = new LinkedList<String>(); String[] mapping = new String[] {"0", "1", "abc", "def", "
2017-09-03 09:40:24 295
原创 650. 2 Keys Keyboard
比如说2为2次才能得到,那么4需要4次,6需要5次,8需要6次。class Solution { public int minSteps(int n) { if(n==1)return 0; int[]dp= new int[n]; for (int i = 0; i < n; i++) { dp[i] = i+
2017-09-01 10:00:22 250
原创 647. Palindromic Substrings
class Solution { public int countSubstrings(String s) { boolean[][] dp = new boolean[s.length()][s.length()]; int result = 0; for (int i = 0; i < s.length(); i++) {
2017-08-19 10:24:18 146
原创 540. Single Element in a Sorted Array
这道题从中间开始找,然后看左边长度是偶数,还是奇数,往是长度是奇数的那边找public class Solution { public int singleNonDuplicate(int[] nums) { int mid = nums.length/2; return findSingle(nums,0,nums.length-1); } p
2017-06-04 19:22:41 222
原创 71. Simplify Path
这道题,比较简单,主要用链表来对路径进行操作,”.”的话,list就直接跳过,”..”的话,list删除尾节点,其他的都是放入尾节点public class Solution { public String simplifyPath(String path) { LinkedList<String > list = new LinkedList<String>();
2017-06-03 15:46:33 183
原创 hive配置
今天花了一个上午配置hive,途中遇到太多的坑,最后总算配置成功了 第一个坑就是我的文件夹是没有hive-default.xml,但他给了hive-defualt的template所以要先输入下面命令cd /usr/local/Cellar/hive/2.1.9/libexec/conf;cp hive-dfault.xml.template hive-defalut.xml,没有这个文件即使配置
2017-04-19 19:35:16 354
原创 mac配置hadoop伪分布式
首先先用brew下载hadoopbrew install hadoop它的xml文件都在/usr/local/Celler/hadoop/2.7.3/libexec/etc/hadoop下 接着一步一步修改文件修改core-site.xml.xml<?xml version="1.0" encoding="UTF-8"?><?xml-stylesheet type="text/xsl" hr
2017-04-14 09:32:43 521
原创 57. Insert Interval
/** * Definition for an interval. * public class Interval { * int start; * int end; * Interval() { start = 0; end = 0; } * Interval(int s, int e) { start = s; end = e; } * } */
2017-03-10 17:55:56 204
原创 306. Additive Number
public class Solution { public boolean isAdditiveNumber(String num) { long first = 0;//这是第一个数 long second = 0;//这是第二个数 long third = 0;//这是第三个数 String values = "";
2017-03-07 16:13:26 186
原创 207. Course Schedule
构造了图结构,在外部用了dfs,最后计算hasCyclepublic class Solution { boolean hasCycle = false; Set set = new HashSet<Integer>(); class DGraph{ int n ; private boolean[] marked; privat
2017-02-26 11:20:28 316
原创 165. Compare Version Numbers
这道题通过“.”划分成数组,在一个一个数组比较public class Solution { public int compareVersion(String version1, String version2) { String []versionl1 = version1.split("\\."); String []versionl2 = version
2017-02-25 15:34:38 187
原创 23. Merge k Sorted Lists
17 ms, 完全的merge方法, 就是将一个数组,不停的分成两个数组,进行合并,基本类似于合并排序/** * Definition for singly-linked list. * public class ListNode { * int val; * ListNode next; * ListNode(int x) { val = x; } * } *
2017-02-01 11:07:56 208
原创 208. Implement Trie (Prefix Tree)
public class Trie { class node{ int count = 0;// 用来删除,计数删除,虽然没有删除 node[] nodes = new node[26]; boolean isEnd = false; } private node root; /** Initialize your da
2017-01-25 14:49:59 171
原创 135. Candy
举一个例子,1,2,3,4,3,4,1 ,小朋友得到的糖分别是1,2,3,4,1,2,1 有特殊情况比如1,2,3,2,2,2小朋友得到的糖是1,2,3,1,1,1; 所以有三种情况一种是递增,一种是递减,一种是相等public class Solution { private int count; public int candy(int[] ratings) {
2017-01-21 14:34:58 184
原创 117. Populating Next Right Pointers in Each Node II
public class Solution { public void connect(TreeLinkNode root) { if (root == null) return; TreeLinkNode pre = root; TreeLinkNode cur = root; TreeLinkNode lastNode = r
2017-01-20 10:04:27 165
原创 131. Palindrome Partitioning
这里我用了搜索,比较常规,关键有一点,你删除之前加入的值,是按索引来删除,而不是删除值,不然顺序会出错。public class Solution { public List<List<String>> partition(String s) { List<List<String>>lists = new ArrayList<>(); List<String
2017-01-14 16:16:11 190
原创 41. First Missing Positive
public class Solution { public int firstMissingPositive(int[] nums) { int count = 0; int start = 0; int end = nums.length - 1; // 这个把负数放到了最后的位置,其实没有必要,管负数,遇到负数直接跳过也行
2017-01-06 11:14:03 199
原创 93. Restore IP Addresses
这道题用的还是搜索,关键是临界条件很重要public class Solution { public List<String> restoreIpAddresses(String s) { List<String>list = new ArrayList<>(); Set<String>set = new HashSet<>(); dfs(se
2017-01-05 12:17:36 155
原创 54. Spiral Matrix
public class Solution { public List<Integer> spiralOrder(int[][] matrix) { List<Integer> list = new ArrayList<>(); //上下左右边界 int down = matrix.length; if(down==0)retur
2017-01-01 10:34:00 178
原创 51. N-Queens
一开始创建一个二维数组,每当放上皇后,就变为true,public class Solution { List<List<String >> lists = new ArrayList<>(); public List<List<String>> solveNQueens(int n) { boolean[][] map = new boolean[n][n];
2016-12-26 15:46:10 201
原创 417. Pacific Atlantic Water Flow
这道题起初我的思路,是深度搜索每一个点,由高往低,看最终是否到达边界,我现在的解参考了标准答案,思路是一样的,当代码也有很多不同,就是从边界开始深搜,用两个数组分别保存能连接p大洋和a大洋的点,如果这个点在这两个数组,这就是我们要找的点。public class Solution { public List<int[]> pacificAtlantic(int[][] matrix) {
2016-12-19 10:54:02 272 1
原创 16. 3Sum Closest
可以把这道题想象成在一条坐标轴上,求三个数之和到目标的距离的最小值,然后再用target加上或减去距离public class Solution { public int threeSumClosest(int[] nums, int target) { Arrays.sort(nums); int i = 0, j = nums.length;
2016-12-16 11:46:09 172
原创 spring redis缓存配置
首先需要Spring Dara Redis<dependencies> <dependency> <groupId>org.springframework.data</groupId> <artifactId>spring-data-redis</artifactId> <version>1.7.5.RELEASE</version>
2016-12-15 20:06:34 368
原创 Spring MVC 4 + Spring Security 4 + Hibernate +JPA实战
最近花了有三个星期把spring实战学了遍,同时也把maven,git,Hibernate给用上了,确实比较锻炼手。登陆,注册(我前端不是很好)是网上找得模版,(提前说下界面做的很挫,是用来练手的,还有很多写的不是很好的代码,我会慢慢完善的,但功能是全的)登陆之后 用来报名考试用的 之后 点了之后,就会扣除你的钱,你也会报名成功。如果不成功就会跳转第一步pom.xml<project
2016-12-14 20:42:18 2154
原创 Trapping Rain Water II
用优先队列,把边沿的墙全加进去,然后从最低的开始,看四周要不要补水。其他的和第一题很像public class Solution { class cell implements Comparable{ int x; int y; int height; public cell(int x, int y, int height) {
2016-12-09 10:44:48 389
原创 cs186-2
我一般不把他写的todo去掉,万一以后改防止改错了。前两个主要实现filter方法,因为后面要用 先放上Predicate.javapackage simpledb;import java.io.Serializable;/** * Predicate compares tuples to a specified Field value. */public class Predicate
2016-11-20 20:52:45 1639 1
翻译 Java NIO(1)
java NIO是由下有下面几个核心组件组成ChannelsBuffersSelectorsChannels and Buffer在NIO中,所有的io都起始于Channel,Channel类似与流,可以读到Buffer中,也可以从Buffer中写入。 这里有些例子,是Channel继承类:FileChannelDatagramChannelSocketChannelServerS
2016-11-13 15:29:36 225
原创 2.6. Operators
public class SeqScan implements DbIterator { private static final long serialVersionUID = 1L; TransactionId tid; int tableid; String tableAlia; DbFile dbFile; DbFileIterator dbFi
2016-11-09 23:43:11 346
原创 Exercise 5
这次感觉比前几次都难,尤其卡在了iterator上,需要反复阅读上面的说明,说明在DbfileIterator上,。详细代码如下HeapFile.java 在文本编译器上删的sout测试语句,可能会带来一些错误,欢迎指正public class HeapFile implements DbFile { /** * Constructs a heap file backed by t
2016-11-08 18:56:13 633
原创 402. Remove K Digits
我才用的是往队列加需要的字母public class Solution { public String removeKdigits(String num, int k) { Queue<Character> queue = new LinkedList<>(); int len = num.length(); int nowLen = len -
2016-11-08 16:56:19 184
原创 42. Trapping Rain Water
public class Solution { public int trap(int[] height) { int first = 0; int last = height.length-1; for(int i=0;i<height.length;i++){ if(height[i]!=0){first=i;brea
2016-11-08 14:18:16 166
原创 233. Number of Digit One
public class Solution { public int countDigitOne(int n) { if(n<=0)return 0; return dfs(n); } private int dfs(int n){ int length = size(n); if(length==1){
2016-11-06 20:21:35 150
原创 2.4. BufferPool 2.5. HeapFile access method
现在还在项目一所以多线程加锁等待这一块没写,一开始没看到写了锁写了很麻烦,才发现不用写,也没测试,所以就没写,等以后做到再加上去。 写BufferPool是用map来缓存数据,但不知道TransactionId在这个函数有什么用,。没用到这个参数,代码如下,其实就两个函数public class BufferPool { /** * Bytes per page, includi
2016-11-06 17:44:32 1102
原创 103. Binary Tree Zigzag Level Order Traversal
/** * Definition for a binary tree node. * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode(int x) { val = x; } * } */public class Solution {
2016-11-05 15:02:52 226
原创 114. Flatten Binary Tree to Linked List
这道题可以发现左子树的最后。连着右子树的开头,所以就设计了一个找到最末点的函数,而dfs的任务是先递归合并左子树,再来合并右子树/** * Definition for a binary tree node. * public class TreeNode { * int val; * TreeNode left; * TreeNode right; *
2016-11-05 13:33:11 234
原创 2.3. Catalog_Exercise 2
The catalog (class Catalog in SimpleDB) consists of a list of the tables and schemas of the tables that are currently in the database. You will need to support the ability to add a new table, as well a
2016-11-05 11:57:13 875
原创 CS186 Project 1: SimpleDB Exercise 1
2.2. Fields and Tuples Tuples in SimpleDB are quite basic. They consist of a collection of Field objects, one per field in the Tuple. Field is an interface that different data types (e.g., integer,
2016-11-05 00:27:07 3805 2
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人