随笔分类 -  Simulation

摘要:public class Solution { public void setZeroes(int[][] matrix) { if(matrix.length==0||matrix[0].length==0) return; boolean row0=false; for(int i=0;i=0;i--) ... 阅读全文
posted @ 2017-09-26 11:36 Weiyu Wang 阅读(135) 评论(0) 推荐(0)
摘要:class Solution { public String simplifyPath(String path) { Stack stack=new Stack(); String[] strs=path.split("\\/"); for(int i=0;i<strs.length;i++) { i... 阅读全文
posted @ 2017-09-26 06:27 Weiyu Wang 阅读(128) 评论(0) 推荐(0)
摘要:class Solution { public List fullJustify(String[] words, int maxWidth) { List res=new ArrayList(); int idx=0; while(idx0) { sb.... 阅读全文
posted @ 2017-09-26 06:19 Weiyu Wang 阅读(137) 评论(0) 推荐(0)
摘要:class Solution { public boolean isNumber(String s) { s=s.trim(); int idx=s.indexOf('e'); if(idx>0) return isNum(s.substring(0,idx), false)&&isNum(s.substring(i... 阅读全文
posted @ 2017-09-26 05:32 Weiyu Wang 阅读(146) 评论(0) 推荐(0)
摘要:public class Solution { public List spiralOrder(int[][] matrix) { List res=new ArrayList(); if(matrix.length==0||matrix[0].length==0) return res; spiralOrder(0... 阅读全文
posted @ 2017-09-26 01:44 Weiyu Wang 阅读(135) 评论(0) 推荐(0)
摘要:public class Solution { public double myPow(double x, int n) { if(n==0) return 1; if(n < 0) return 1/(x*myPow(x, -(n+1))); double t = myPow(x,n/2)... 阅读全文
posted @ 2017-09-25 09:17 Weiyu Wang 阅读(154) 评论(0) 推荐(0)
摘要:class Solution { public List> groupAnagrams(String[] strs) { Map> map=new HashMap>(); for(String str: strs) { char[] arr=str.toCharArray(); Arrays.... 阅读全文
posted @ 2017-09-25 08:59 Weiyu Wang 阅读(116) 评论(0) 推荐(0)
摘要:class Solution { public void rotate(int[][] matrix) { int n=matrix.length; for(int i=0;i<n;i++) for(int j=i+1;j<n;j++) swap(matrix,i,j,j,i); fo... 阅读全文
posted @ 2017-09-25 08:54 Weiyu Wang 阅读(119) 评论(0) 推荐(0)
摘要:public class Solution { public String multiply(String num1, String num2) { int[] digits=new int[num1.length()+num2.length()]; for(int i=0;i=0;i--) { if(i>0) ... 阅读全文
posted @ 2017-09-24 14:04 Weiyu Wang 阅读(151) 评论(0) 推荐(0)
摘要:public class Solution { public boolean isValidSudoku(char[][] board) { boolean[][][] used=new boolean[3][9][9]; for(int i=0;i<9;i++) for(int j=0;j<9;j++) ... 阅读全文
posted @ 2017-09-23 13:43 Weiyu Wang 阅读(128) 评论(0) 推荐(0)
摘要:public class Solution { public int divide(int dividend, int divisor) { boolean isNegtive=dividend0||dividend>0&&divisor=ldivisor) { if(ldividend>=l) { ... 阅读全文
posted @ 2017-09-23 06:22 Weiyu Wang 阅读(141) 评论(0) 推荐(0)
摘要:class Solution { public String intToRoman(int num) { String[][] r=new String[][]{{"","M","MM","MMM"}, {"","C","CC","CCC","CD","D","DC","DCC","DCCC","CM"}, ... 阅读全文
posted @ 2017-09-22 12:12 Weiyu Wang 阅读(123) 评论(0) 推荐(0)
摘要:Recursive DP 阅读全文
posted @ 2017-09-22 04:31 Weiyu Wang 阅读(169) 评论(0) 推荐(0)
摘要:class Solution { public int myAtoi(String str) { str=str.trim(); if(str.length()==0) return 0; int flag=1; int i=0; if(str.charAt(i)=='+') ... 阅读全文
posted @ 2017-09-22 02:18 Weiyu Wang 阅读(131) 评论(0) 推荐(0)
摘要:class Solution { public String convert(String s, int numRows) { if(numRows==1) return s; int divisor=(numRows-1)*2; StringBuilder sb=new StringBuilder(); ... 阅读全文
posted @ 2017-09-22 01:53 Weiyu Wang 阅读(88) 评论(0) 推荐(0)
摘要:class Solution { public ListNode addTwoNumbers(ListNode l1, ListNode l2) { ListNode ret=new ListNode(0); ListNode l3=ret; int carry=0; while(l1!=null||l2!=null||ca... 阅读全文
posted @ 2017-09-21 05:39 Weiyu Wang 阅读(117) 评论(0) 推荐(0)
摘要:模拟类DescriptionThis problem is a reverse case of the problem 2996. You are given the output of the problem H and your task is to find the corresponding input.  Inputaccording to output of problem ... 阅读全文
posted @ 2009-09-29 03:33 Weiyu Wang 阅读(412) 评论(0) 推荐(0)
摘要:模拟类DescriptionYour task is to read a picture of a chessboard position and print it in the chess notation. InputThe input consists of an ASCII-art picture of a chessboard with chess pieces on posi... 阅读全文
posted @ 2009-09-29 01:56 Weiyu Wang 阅读(589) 评论(0) 推荐(0)
摘要:模拟类DescriptionA robot has been programmed to follow the instructions in its path. Instructions for the next direction the robot is to move are laid down in a grid. The possible instructions are N nort... 阅读全文
posted @ 2009-09-29 00:42 Weiyu Wang 阅读(336) 评论(0) 推荐(0)
摘要:模拟类DescriptionIn a modernized warehouse, robots are used to fetch the goods. Careful planning is needed to ensure that the robots reach their destinations without crashing into each other. Of course, ... 阅读全文
posted @ 2009-09-28 23:28 Weiyu Wang 阅读(488) 评论(0) 推荐(0)