自定义博客皮肤VIP专享

*博客头图:

格式为PNG、JPG,宽度*高度大于1920*100像素,不超过2MB,主视觉建议放在右侧,请参照线上博客头图

请上传大于1920*100像素的图片!

博客底图:

图片格式为PNG、JPG,不超过1MB,可上下左右平铺至整个背景

栏目图:

图片格式为PNG、JPG,图片宽度*高度为300*38像素,不超过0.5MB

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+
  • 博客(43)
  • 收藏
  • 关注

转载 mysql增删改查的封装

package cn.zcw.util;import java.sql.Connection;import java.sql.PreparedStatement;import java.sql.ResultSet;import java.sql.SQLException;import java.util.ArrayList;import java.util.List

2017-12-07 19:33:59 366

转载 JdbcUtil的封装

package cn.zcw.util;import java.io.IOException;import java.io.InputStream;import java.sql.Connection;import java.sql.DriverManager;import java.sql.PreparedStatement;import java.sql

2017-12-07 19:32:13 209

转载 Leetcode 201. Bitwise AND of Numbers Range

第二种方法速度更快1.public int rangeBitwiseAnd(int m, int n) {int i = 0;while (m != n) {m = m >> 1;n = n >> 1;i++;}return m }2.public int rangeBitwiseAnd(int m, int n)

2017-10-25 11:10:18 118

原创 Leetcode 199. Binary Tree Right Side View

1. public List rightSideView(TreeNode root) {        List res=new ArrayList(); rightView(root,res,0); return res;    }        public void rightView(TreeNode cur, List res, int i) {

2017-10-25 09:25:06 149

转载 Leetcode 198. House Robber

这道题应用动态规划的思想求解,动态规划需要注意的一个地方是数组有时没必要,可以用常量代替。public int rob1(int[] nums){int[][] dp=new int[nums.length+1][2];for(int i=1;idp[i][0]=Math.max(dp[i-1][0], dp[i-1][1]);dp[i][1]=dp[i-1][0]+n

2017-10-24 10:41:04 157

转载 Leetcode 190. Reverse Bits

public int reverseBits(int n) {int result = 0;for (int i = 0; i result = result result+=n&1;n = n >> 1;}return result;}

2017-10-23 10:37:02 116

转载 Leetcode 189. Rotate Array

1.public void rotate(int[] nums, int k) {if(nums.lengthreturn;}int n=nums.length;int step=k%nums.length;int[] tmp=new int[step];for(int i=0;itmp[i]=nums[n-step+i];}for(int i=

2017-10-22 19:59:36 91

转载 Leetcode 188. Best Time to Buy and Sell Stock IV

public int maxProfit(int k, int[] prices) { int n = prices.length; if (n 1) return 0; //if k >= n/2, then you can make maximum number of transactions. if (k >= n/2) { int maxPro = 0; for

2017-10-21 21:33:02 137

转载 leetcode 187. Repeated DNA Sequences

class Solution {    public List findRepeatedDnaSequences(String s) {List res = new ArrayList();Map map = new HashMap();if (s.length() return res;}int key = 0;for (int i = 0; i

2017-10-20 20:12:02 113

原创 179. Largest Number

public String largestNumber(int[] nums) {if(nums==null || nums.length==0){return "";}String[] strs=new String[nums.length];int count=0;for(int i=0;iif(nums[i]==0){count++;}strs[i

2017-10-12 20:10:54 110

转载 166. Fraction to Recurring Decimal

public String fractionToDecimal(int numerator, int denominator) {if(denominator==0){return "";}if(numerator==0){return "0";}String res="";if((numeratorres+="-";}long num=nume

2017-10-06 10:20:14 109

转载 leetcode 154.Find Minimum in Rotated Sorted Array II

public int findMin(int[] num) { 3 if (num == null || num.length == 0) { 4 return 0; 5 } 6 7 int len = num.length; 8 if (len == 1) { 9

2017-09-27 11:38:55 93

原创 python爬取图片

import urllib.requestimport redef getHtml(url):    page = urllib.request.urlopen(url)    html = page.read()        return htmldef getImg(html):    html=html.decode('utf-8')

2017-09-23 10:56:52 311

原创 leetcode 151. Reverse Words in a String

本题难度不大,核心在于对于小细节的处理,字符串的预处理很重要public class Solution {        public void reverseArray(String[] words) {int i = 0, n = words.length - 1;while (n > 2 * i) {String x = words[i];words[i]

2017-09-23 10:23:28 106

原创 python生成随机图片验证码

from PIL import Image,ImageDraw,ImageFont,ImageFilterimport randomimport stringchars=string.digits+string.ascii_letterschars=random.sample(chars,4)print(chars)def rndColor():  #产生随机颜色   

2017-09-19 11:19:26 1940

原创 链表的归并排序算法

public static ListNode mergeTwoList(ListNode headA,ListNode headB){ListNode rehead=new ListNode(0);ListNode pre=rehead;while(headA!=null && headB!=null){if(headA.valpre.next=headA;headA=he

2017-09-19 10:14:43 323

转载 python统计代码空行与注释

#_*_coding:utf-8_*_# 统计代码行数, 空行, 注释.import osdef code_lines_count(path):    code_lines = 0    comm_lines = 0    space_lines = 0        for root,dirs,files in os.walk(path):   

2017-09-18 10:27:39 572

转载 147. Insertion Sort List

public ListNode insertionSortList(ListNode head) {if(head==null){return null;}if(head.next==null){return head;}ListNode rehead=new ListNode(-1);rehead.next=head;ListNode pre=head;L

2017-09-17 21:56:48 214

原创 LRU Cache leetcode

1.自己想的  public class LRUCache {public LinkedList used=new LinkedList();public Map map=new HashMap();public int len;public int capacity;public LRUCache(int capacity) {this.capacity = capa

2017-09-16 10:52:41 136

原创 143. Reorder List

本题比较难想,关键是要找到思路。思路是按照三步来,  1.找到中间节点,断开。  2.把后半截单链表 反转一下一下。  3.再合并两个单链表。public void reorderList(ListNode head) {if(head==null){return;}ListNode slow=head;ListNode fast=head;while(

2017-09-14 10:15:21 142

转载 142. Linked List Cycle II

设:链表头是X,环的第一个节点是Y,slow和fast第一次的交点是Z。各段的长度分别是a,b,c,如图所示。环的长度是L。slow和fast的速度分别是qs,qf。第一次相遇时slow走过的距离:a+b,fast走过的距离:a+b+c+b。因为fast的速度是slow的两倍,所以fast走的距离是slow的两倍,有 2(a+b) = a+b+c+b,可以得到a=c(这个结论很重要!)

2017-09-13 11:22:06 116

转载 leetcode 140. Word Break II

140. Word Break II           public boolean wordBreakcheck(String s, List dict) {if (s == null || s.length() == 0)return true;boolean[] res = new boolean[s.length() + 1];res[0] = true;

2017-09-12 10:35:14 121

转载 139. Word Break

1.对于这个问题首先想到的是递归方法,关于遍历的问题,不一定非要通过字符串下标来遍历字符串,通过遍历字典中的字符串更简洁明了,但是一般来说递归总是会有超时问题,遇到这种问题尽量使用动态规划方法:  public boolean wordBreak(String s, List wordDict) {if(wordDict.size()==0){return false;}if(

2017-09-11 09:54:35 127

转载 Leetcode 138. Copy List with Random Pointer

1.本道题的目标是对链表进行深度复制,首先第一种解法是利用map方便操作。旧结点为key,新节点为value。这么做的目的是为了第二遍扫描的时候我们按照这个哈希表把结点的随机指针接上。时间复杂度为O(n),空间复杂度为O(n)。  public RandomListNode copyRandomList(RandomListNode head) { if(head == null)

2017-09-10 10:11:31 106

转载 Leetcode 132. Palindrome Partitioning II

public int minCut(String s) {        int min = 0;int len = s.length() ;boolean[][] matrix = new boolean[len][len];int[] cuts = new int[len + 1];if (s.length() == 0 || s == null) {r

2017-09-03 11:08:32 87

转载 Leetcode 120. Triangle

解法一:给出一个三角形状的整数list,从第一行向下移动,每次只能向下一行相邻的数移动,要求求出从第一行到最后一行所经过的数字的和最小的方法。这是一道动态规划的题目,第一种解法可以用一个二维数组存储从第一行到某行某个数的经过数的最小值,这是空间为o(n*n),对其中第i行(i>1)的第j个数(0  利用动态规划常规思想去解从上到下,但是有个问题就是由于是三角形形数据,二维数组不少空间都

2017-09-02 11:21:02 95

转载 Leetcode 131. Palindrome Partitioning

public void solve(char[][] board) {if(board==null || board.lengthreturn;}for(int i=0;ifill(board, 0, i);fill(board, board.length-1, i);}for(int i=0;ifill(board, i, 0);fill(board, i

2017-08-30 10:33:55 123

转载 128. Longest Consecutive Sequence

public int longestConsecutive(int[] nums) {        if(nums==null || nums.length==0){            return 0;        }        HashSet set=new HashSet();int len=1;for(int e:nums){set.add(e)

2017-08-29 11:12:47 144

转载 leetcode 130. Surrounded Regions

public void solve(char[][] board) {if(board==null || board.lengthreturn;}for(int i=0;ifill(board, 0, i);fill(board, board.length-1, i);}for(int i=0;ifill(board, i, 0);fill(board, i

2017-08-29 11:10:37 137

原创 Leetcode Best Time to Buy and Sell Stock III

题目要求限定两次交易求最大收益,解决方法自然应该想到了二分法和动态规划public int maxProfit(int[] prices) {if(prices==null || prices.lengthreturn 0;}int n=prices.length;int[] preProfit=new int[n];int[] postProfit=new int[n

2017-08-21 11:36:12 109

原创 Leetcode 97Interleaving String

本题核心思想是动态规划,涉及此类问题尽量不要用递归。public boolean isInterleave(String s1, String s2, String s3) {// Note: The Solution object is instantiated only once and is reused by each test case.          if (s

2017-08-08 21:24:56 113

原创 93. Restore IP Addresses

这道题核心思想是DFS求解,一个IP地址有四段,每段有1到3个字符,public List restoreIpAddresses(String s) {List res = new ArrayList();if (s == null || s.length() 12) {return res;}StringBuffer tmp = new String

2017-08-07 10:53:58 84

转载 Leetcode 91. Decode Ways

if(s==null || s.length()==0) {            return 0;        }        if(s.charAt(0)=='0') {            return 0;        }                int [] number = new int[s.length() + 1];       

2017-08-05 10:26:07 128

原创 Scramble String 动态规划

动态规划问题,涉及到动态规划问题基本思想是尽量使用数组   public boolean isScramble(String s1, String s2) {                        if (s1.length() != s2.length()) {return false;}int n = s1.length();if (s1.equal

2017-07-30 11:06:37 226

原创 82. Remove Duplicates from Sorted List II

82. Remove Duplicates f rom Sorted List II三刷

2017-07-25 10:18:45 153

原创 关于Spring MVC的一个经验

今天在写一个JSON数据传输案例时,按照书上写的代码是死活跑不通,后来网上查了,是xml文件配置问题,只配置了org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter,却没有配置org.springframework.web.servlet.mvc.method.annotation.Req

2017-07-24 14:36:28 146

原创 leetcode经典组合类问题,采用dfs思想

public class Solution {    public List> combine(int n, int k) {                 List> combSet=new ArrayList>();         List comb=new ArrayList();         if(n             return combSet;

2017-07-22 09:51:11 180

原创 leetcode 72 edit distance

求两个字符串的编辑距离。核心思想依然是动态规划,但是递归的时间复杂度太大,尽量用数组解决这种问题。public int minDistance(String word1, String word2) {                int len1=word1.length()+1;        int len2=word2.length()+1;        int

2017-07-17 10:41:59 145

原创 leetcode 70. Climbing Stairs

这个问题是比较典型的动态规划问题,到达第n个台阶时的走法是第n-1个台阶和n-2个台阶步数之和。      public int climbStairs(int n) {        int[] res=new int[n+1];        res[0]=1;        res[1]=1;        for(int i=2;i            res

2017-07-15 19:51:47 102

原创 67. Add Binary ershua二刷

public class Solution { public String addBinary(String a, String b) { if(a == null || a.isEmpty()) { return b; } if(b == null || b.isEmpty()) { retu

2017-07-11 11:09:33 213

空空如也

空空如也

TA创建的收藏夹 TA关注的收藏夹

TA关注的人

提示
确定要删除当前文章?
取消 删除