JasonChang

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

2013年11月5日

摘要: recursion programming 1 /** 2 * Definition for singly-linked list. 3 * public class ListNode { 4 * int val; 5 * ListNode next; 6 * ListNode(int x) { 7 * val = x; 8 * next = null; 9 * }10 * }11 */12 public class Solution {13 public ListNode swapPairs(List... 阅读全文
posted @ 2013-11-05 14:56 JasonChang 阅读(160) 评论(0) 推荐(0) 编辑

摘要: fastrunner and slowrunner trick.(be care of head node) 1 /** 2 * Definition for singly-linked list. 3 * public class ListNode { 4 * int val; 5 * ListNode next; 6 * ListNode(int x) { 7 * val = x; 8 * next = null; 9 * }10 * }11 */12 public class Solution {13 ... 阅读全文
posted @ 2013-11-05 14:37 JasonChang 阅读(153) 评论(0) 推荐(0) 编辑

摘要: recursion problem 1 public class Solution { 2 public ArrayList letterCombinations(String digits) { 3 // IMPORTANT: Please reset any member data you declared, as 4 // the same Solution instance will be reused for each test case. 5 ArrayList result = new ArrayList(); 6 ... 阅读全文
posted @ 2013-11-05 14:07 JasonChang 阅读(205) 评论(0) 推荐(0) 编辑

摘要: similar with 3Sum 1 public class Solution { 2 public int threeSumClosest(int[] num, int target) { 3 // IMPORTANT: Please reset any member data you declared, as 4 // the same Solution instance will be reused for each test case. 5 if(num == null || num.length < 3) 6 ... 阅读全文
posted @ 2013-11-05 13:47 JasonChang 阅读(141) 评论(0) 推荐(0) 编辑

摘要: 1 public class Solution { 2 public ArrayList generateParenthesis(int n) { 3 // IMPORTANT: Please reset any member data you declared, as 4 // the same Solution instance will be reused for each test case. 5 ArrayList result = new ArrayList(); 6 StringBuilder builde... 阅读全文
posted @ 2013-11-05 12:19 JasonChang 阅读(192) 评论(0) 推荐(0) 编辑

摘要: 1 /** 2 * Definition for singly-linked list. 3 * public class ListNode { 4 * int val; 5 * ListNode next; 6 * ListNode(int x) { 7 * val = x; 8 * next = null; 9 * }10 * }11 */12 public class Solution {13 public ListNode mergeTwoLists(ListNode l1, ListNode... 阅读全文
posted @ 2013-11-05 12:05 JasonChang 阅读(154) 评论(0) 推荐(0) 编辑

摘要: use stack (be careful of empty stack) 1 public class Solution { 2 public boolean isValid(String s) { 3 // IMPORTANT: Please reset any member data you declared, as 4 // the same Solution instance will be reused for each test case. 5 if(s == null||s.length() == 0) 6 ... 阅读全文
posted @ 2013-11-05 11:54 JasonChang 阅读(169) 评论(0) 推荐(0) 编辑

摘要: be careful of the special cases(null, 0) 1 public class Solution { 2 public String longestCommonPrefix(String[] strs) { 3 // IMPORTANT: Please reset any member data you declared, as 4 // the same Solution instance will be reused for each test case. 5 if(strs == null||strs... 阅读全文
posted @ 2013-11-05 11:39 JasonChang 阅读(186) 评论(0) 推荐(0) 编辑

摘要: 当前一位小于后一位的时候才是后一位减去前一位,并且这种位数只有一位 1 public class Solution { 2 public int romanToInt(String s) { 3 // IMPORTANT: Please reset any member data you declared, as 4 // the same Solution instance will be reused for each test case. 5 int result = 0; 6 if (s == null || s.... 阅读全文
posted @ 2013-11-05 09:38 JasonChang 阅读(160) 评论(0) 推荐(0) 编辑

摘要: use stringbuffer 1 public class Solution { 2 public String intToRoman(int num) { 3 // IMPORTANT: Please reset any member data you declared, as 4 // the same Solution instance will be reused for each test case. 5 StringBuffer result = new StringBuffer(); 6 String[]... 阅读全文
posted @ 2013-11-05 09:18 JasonChang 阅读(139) 评论(0) 推荐(0) 编辑