10 2017 档案

摘要:public class Solution { public int rangeBitwiseAnd(int m, int n) { int r=Integer.MAX_VALUE; while((m&r)!=(n&r)) r=r<<1; return n&r; } } 阅读全文
posted @ 2017-10-31 13:08 Weiyu Wang 阅读(113) 评论(0) 推荐(0)
摘要:class Solution { public int numIslands(char[][] grid) { int count=0; for(int i=0;i=grid.length||j=grid[0].length||grid[i][j]!='1') return; grid[i][j]='2'; ... 阅读全文
posted @ 2017-10-26 01:48 Weiyu Wang 阅读(124) 评论(0) 推荐(0)
摘要:class Solution { public List rightSideView(TreeNode root) { List res=new ArrayList(); rightView(root, res, 0); return res; } private void rightView(TreeNode node, ... 阅读全文
posted @ 2017-10-26 01:31 Weiyu Wang 阅读(135) 评论(0) 推荐(0)
摘要:class Solution { public int maxProfit(int k, int[] prices) { if(k>=prices.length/2) { int maxProfit=0; for(int i=1;iprices[i-1]?prices[i]-prices[i-1]:0; ... 阅读全文
posted @ 2017-10-26 01:19 Weiyu Wang 阅读(143) 评论(0) 推荐(0)
摘要:class Solution { public List findRepeatedDnaSequences(String s) { Set set=new HashSet(); Set res=new HashSet(); for(int i=0;i+10(res); } } 阅读全文
posted @ 2017-10-26 01:18 Weiyu Wang 阅读(120) 评论(0) 推荐(0)
摘要:ph 阅读全文
posted @ 2017-10-26 01:17 Weiyu Wang 阅读(100) 评论(0) 推荐(0)
摘要:select d.Name Department, e1.Name Employee, e1.Salary from Employee e1 join Department d on e1.DepartmentId = d.Id where 3 > (select count(distinct(e2.Salary)) from Employee e2 ... 阅读全文
posted @ 2017-10-25 04:41 Weiyu Wang 阅读(110) 评论(0) 推荐(0)
摘要:SELECT dep.Name as Department, emp.Name as Employee, emp.Salary from Department dep, Employee emp where emp.DepartmentId=dep.Id and emp.Salary=(Select max(Salary) from Employee e2 where e2.Departm... 阅读全文
posted @ 2017-10-25 04:40 Weiyu Wang 阅读(74) 评论(0) 推荐(0)
摘要:Select DISTINCT l1.Num from Logs l1, Logs l2, Logs l3 where l1.Id=l2.Id-1 and l2.Id=l3.Id-1 and l1.Num=l2.Num and l2.Num=l3.Num 阅读全文
posted @ 2017-10-25 04:39 Weiyu Wang 阅读(117) 评论(0) 推荐(0)
摘要:class Solution { public String largestNumber(int[] nums) { String[] arr=new String[nums.length]; for(int i=0;i{return new String(b+a).compareTo(a+b);}); if(arr[0].charAt(0... 阅读全文
posted @ 2017-10-25 04:35 Weiyu Wang 阅读(96) 评论(0) 推荐(0)
摘要:SELECT Score, (SELECT count(distinct Score) FROM Scores WHERE Score >= s.Score) Rank FROM Scores s ORDER BY Score desc 阅读全文
posted @ 2017-10-25 03:13 Weiyu Wang 阅读(102) 评论(0) 推荐(0)
摘要:CREATE FUNCTION getNthHighestSalary(N INT) RETURNS INT BEGIN DECLARE M INT; SET M=N-1; RETURN ( # Write your MySQL query statement below. SELECT DISTINCT Salary FROM Employee ORDER BY S... 阅读全文
posted @ 2017-10-25 03:10 Weiyu Wang 阅读(243) 评论(0) 推荐(0)
摘要:class Solution { public int calculateMinimumHP(int[][] dungeon) { if(dungeon.length==0||dungeon[0].length==0) return 0; int M=dungeon.length; int N=dungeon[0].... 阅读全文
posted @ 2017-10-25 02:55 Weiyu Wang 阅读(94) 评论(0) 推荐(0)
摘要:/** * Definition for binary tree * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode(int x) { val = x; } * } */ public class BSTIterator { ... 阅读全文
posted @ 2017-10-25 01:00 Weiyu Wang 阅读(107) 评论(0) 推荐(0)
摘要:class Solution { public String fractionToDecimal(int numerator, int denominator) { StringBuilder sb=new StringBuilder(); if(numerator0||numerator>0&&denominator0) sb.a... 阅读全文
posted @ 2017-10-24 07:13 Weiyu Wang 阅读(94) 评论(0) 推荐(0)
摘要:class Solution { public int compareVersion(String version1, String version2) { String[] v1=version1.split("\\."); String[] v2=version2.split("\\."); int i=0; ... 阅读全文
posted @ 2017-10-24 04:40 Weiyu Wang 阅读(118) 评论(0) 推荐(0)
摘要:class Solution { public int maximumGap(int[] nums) { if(nums.length<2) return 0; int max=Integer.MIN_VALUE; int min=Integer.MAX_VALUE; for(int num:nums... 阅读全文
posted @ 2017-10-24 04:27 Weiyu Wang 阅读(139) 评论(0) 推荐(0)
摘要:ph 阅读全文
posted @ 2017-10-24 01:21 Weiyu Wang 阅读(147) 评论(0) 推荐(0)
摘要:class Solution { public int findPeakElement(int[] nums) { for(int i=0;i0&&nums[i]>nums[i-1])&&(i==nums.length-1||inums[i+1])) return i; return -1; } } 阅读全文
posted @ 2017-10-24 01:20 Weiyu Wang 阅读(101) 评论(0) 推荐(0)
摘要:ph 阅读全文
posted @ 2017-10-24 01:09 Weiyu Wang 阅读(232) 评论(0) 推荐(0)
摘要:ph 阅读全文
posted @ 2017-10-24 01:07 Weiyu Wang 阅读(101) 评论(0) 推荐(0)
摘要:ph 阅读全文
posted @ 2017-10-24 01:07 Weiyu Wang 阅读(129) 评论(0) 推荐(0)
摘要:ph 阅读全文
posted @ 2017-10-24 01:06 Weiyu Wang 阅读(96) 评论(0) 推荐(0)
摘要:class Solution { public int findMin(int[] nums) { int lo=0; int hi=nums.length-1; while(lonums[hi]) lo=mid+1; else hi--; ... 阅读全文
posted @ 2017-10-24 01:05 Weiyu Wang 阅读(131) 评论(0) 推荐(0)
摘要:class Solution { public int findMin(int[] nums) { int lo=0; int hi=nums.length-1; while(lo<hi) { int mid=(lo+hi)/2; if(nums[mid]<nums[hi]) ... 阅读全文
posted @ 2017-10-24 01:02 Weiyu Wang 阅读(169) 评论(0) 推荐(0)
摘要:class Solution { public int maxProduct(int[] nums) { int res=nums[0]; for(int i=1, imax=res,imin=res;i<nums.length;i++) { int cmax=Math.max(nums[i]*imax,nums[i... 阅读全文
posted @ 2017-10-18 06:38 Weiyu Wang 阅读(113) 评论(0) 推荐(0)
摘要:public class Solution { public String reverseWords(String s) { char[] arr=s.toCharArray(); reverse(arr, 0, arr.length-1); int i=0; int j=0; while(j0&&i<=ar... 阅读全文
posted @ 2017-10-18 05:54 Weiyu Wang 阅读(90) 评论(0) 推荐(0)
摘要:class Solution { public int evalRPN(String[] tokens) { Stack stack=new Stack(); for(String token:tokens) { if(token.equals("+")||token.equals("-")||token.equal... 阅读全文
posted @ 2017-10-17 10:40 Weiyu Wang 阅读(115) 评论(0) 推荐(0)
摘要:class Solution { public int maxPoints(Point[] points) { if(points.length> map=new HashMap>(); for(int i=0;i m = new HashMap(); m.put(y, 1); map.put(x, m); ... 阅读全文
posted @ 2017-10-17 08:02 Weiyu Wang 阅读(106) 评论(0) 推荐(0)
摘要:class Solution { public ListNode sortList(ListNode head) { if(head==null||head.next==null) return head; ListNode p=head,q=head; while(p.next!=null&&p.next.next... 阅读全文
posted @ 2017-10-17 04:58 Weiyu Wang 阅读(98) 评论(0) 推荐(0)
摘要:class Solution { public ListNode insertionSortList(ListNode head) { ListNode pre=new ListNode(0); ListNode p=head, q; while(p!=null) { q=pre; ... 阅读全文
posted @ 2017-10-17 04:41 Weiyu Wang 阅读(119) 评论(0) 推荐(0)
摘要:class LRUCache { class DNode{ public int val; public int key; public DNode pre; public DNode next; public DNode(int k, int v){ key=k; ... 阅读全文
posted @ 2017-10-17 04:26 Weiyu Wang 阅读(122) 评论(0) 推荐(0)
摘要:class Solution { public List postorderTraversal(TreeNode root) { Stack stack=new Stack(); List res=new ArrayList(); while(root!=null||!stack.isEmpty()) { ... 阅读全文
posted @ 2017-10-17 03:21 Weiyu Wang 阅读(114) 评论(0) 推荐(0)
摘要:class Solution { public List preorderTraversal(TreeNode root) { Stack stack=new Stack(); List res=new ArrayList(); while(root!=null||!stack.isEmpty()) { ... 阅读全文
posted @ 2017-10-12 06:04 Weiyu Wang 阅读(81) 评论(0) 推荐(0)
摘要:class Solution { public void reorderList(ListNode head) { ListNode p=head, q=head; while(p!=null&&p.next!=null) { p=p.next.next; q=q.next; ... 阅读全文
posted @ 2017-10-12 05:58 Weiyu Wang 阅读(124) 评论(0) 推荐(0)
摘要:public class Solution { public ListNode detectCycle(ListNode head) { ListNode p=head,q=head; while(p!=null&&p.next!=null) { p=p.next.next; q=q.next... 阅读全文
posted @ 2017-10-10 12:30 Weiyu Wang 阅读(121) 评论(0) 推荐(0)
摘要:class Solution { public List wordBreak(String s, List wordDict) { Map> map=new HashMap>(); wordBreak(s, map, wordDict); return map.get(s); } private void wordBreak... 阅读全文
posted @ 2017-10-10 12:20 Weiyu Wang 阅读(140) 评论(0) 推荐(0)
摘要:class Solution { public boolean wordBreak(String s, List wordDict) { boolean[] dp=new boolean[s.length()+1]; dp[0]=true; for(int i=0;i=0&&w.equals(s.substring(i+1-w.length... 阅读全文
posted @ 2017-10-10 03:50 Weiyu Wang 阅读(125) 评论(0) 推荐(0)
摘要:public class Solution { public RandomListNode copyRandomList(RandomListNode head) { Map map=new HashMap(); RandomListNode p=new RandomListNode(0); p.next=head; Ran... 阅读全文
posted @ 2017-10-10 02:45 Weiyu Wang 阅读(118) 评论(0) 推荐(0)
摘要:class Solution { public int singleNumber(int[] nums) { int res=0; for(int i=0;i>i)&1; res|=(sum%3)<<i; } return res; } } 阅读全文
posted @ 2017-10-08 12:20 Weiyu Wang 阅读(104) 评论(0) 推荐(0)
摘要:class Solution { public int candy(int[] ratings) { int[] candies=new int[ratings.length]; for(int i=0;i=0;i--) if(ratings[i]>ratings[i+1]) candies[i]=M... 阅读全文
posted @ 2017-10-08 12:10 Weiyu Wang 阅读(153) 评论(0) 推荐(0)
摘要:class Solution { public int canCompleteCircuit(int[] gas, int[] cost) { int total=0,cur=0,start=0; for(int i=0;i=0?start:-1; } } 阅读全文
posted @ 2017-10-07 05:07 Weiyu Wang 阅读(143) 评论(0) 推荐(0)
摘要:public class Solution { public UndirectedGraphNode cloneGraph(UndirectedGraphNode node) { if(node==null) return null; Map map=new HashMap(); Queue que=new Link... 阅读全文
posted @ 2017-10-07 04:47 Weiyu Wang 阅读(131) 评论(0) 推荐(0)
摘要:class Solution { public int minCut(String s) { int[] dp=new int[s.length()+1]; for(int i=0;i=0&&i+len=0&&i+len<s.length()&&s.charAt(i-1-len)==s.charAt(i+len);len++) ... 阅读全文
posted @ 2017-10-05 04:23 Weiyu Wang 阅读(145) 评论(0) 推荐(0)
摘要:class Solution { public List> partition(String s) { List> res=new ArrayList>(); generatePartition(0,new ArrayList(),res,s); return res; } private void generatePart... 阅读全文
posted @ 2017-10-05 01:43 Weiyu Wang 阅读(122) 评论(0) 推荐(0)
摘要:public class Solution { public void solve(char[][] board) { if (board.length == 0 || board[0].length == 0) return; int m = board.length; int n = board[0].length; bool... 阅读全文
posted @ 2017-10-04 10:54 Weiyu Wang 阅读(113) 评论(0) 推荐(0)
摘要:class Solution { public int sumNumbers(TreeNode root) { return sumNumber("", root); } private int sumNumber(String str, TreeNode node){ if(node==null) return 0... 阅读全文
posted @ 2017-10-04 05:44 Weiyu Wang 阅读(129) 评论(0) 推荐(0)
摘要:class Solution { public int longestConsecutive(int[] nums) { Set set=new HashSet(); for(int num:nums) set.add(num); int res=0; for(int num:set) ... 阅读全文
posted @ 2017-10-04 05:36 Weiyu Wang 阅读(132) 评论(0) 推荐(0)
摘要:class Solution { public int ladderLength(String beginWord, String endWord, List wordList) { Set dict=new HashSet(wordList); if(!dict.contains(endWord)) return 0; ... 阅读全文
posted @ 2017-10-04 05:27 Weiyu Wang 阅读(147) 评论(0) 推荐(0)
摘要:class Solution { public List> findLadders(String beginWord, String endWord, List wordList) { List> res=new ArrayList>(); Set dict=new HashSet(wordList); if(!dict.contains(... 阅读全文
posted @ 2017-10-04 05:09 Weiyu Wang 阅读(173) 评论(0) 推荐(0)
摘要:class Solution { int maxPathSum; public int maxPathSum(TreeNode root) { maxPathSum=Integer.MIN_VALUE; seachPathSum(root); return maxPathSum; } private int seac... 阅读全文
posted @ 2017-10-03 02:12 Weiyu Wang 阅读(126) 评论(0) 推荐(0)
摘要:压缩 阅读全文
posted @ 2017-10-02 03:22 Weiyu Wang 阅读(124) 评论(0) 推荐(0)