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; } }
阅读全文
摘要: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'; ...
阅读全文
摘要:class Solution { public List rightSideView(TreeNode root) { List res=new ArrayList(); rightView(root, res, 0); return res; } private void rightView(TreeNode node, ...
阅读全文
摘要: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; ...
阅读全文
摘要:class Solution { public List findRepeatedDnaSequences(String s) { Set set=new HashSet(); Set res=new HashSet(); for(int i=0;i+10(res); } }
阅读全文
摘要: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 ...
阅读全文
摘要: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...
阅读全文
摘要: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
阅读全文
摘要: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...
阅读全文
摘要:SELECT Score, (SELECT count(distinct Score) FROM Scores WHERE Score >= s.Score) Rank FROM Scores s ORDER BY Score desc
阅读全文
摘要: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...
阅读全文
摘要: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]....
阅读全文
摘要:/** * Definition for binary tree * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode(int x) { val = x; } * } */ public class BSTIterator { ...
阅读全文
摘要:class Solution { public String fractionToDecimal(int numerator, int denominator) { StringBuilder sb=new StringBuilder(); if(numerator0||numerator>0&&denominator0) sb.a...
阅读全文
摘要:class Solution { public int compareVersion(String version1, String version2) { String[] v1=version1.split("\\."); String[] v2=version2.split("\\."); int i=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...
阅读全文
摘要: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; } }
阅读全文
摘要:class Solution { public int findMin(int[] nums) { int lo=0; int hi=nums.length-1; while(lonums[hi]) lo=mid+1; else hi--; ...
阅读全文
摘要: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]) ...
阅读全文
摘要: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...
阅读全文
摘要: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...
阅读全文
摘要:class Solution { public int evalRPN(String[] tokens) { Stack stack=new Stack(); for(String token:tokens) { if(token.equals("+")||token.equals("-")||token.equal...
阅读全文
摘要: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); ...
阅读全文
摘要: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...
阅读全文
摘要:class Solution { public ListNode insertionSortList(ListNode head) { ListNode pre=new ListNode(0); ListNode p=head, q; while(p!=null) { q=pre; ...
阅读全文
摘要:class LRUCache { class DNode{ public int val; public int key; public DNode pre; public DNode next; public DNode(int k, int v){ key=k; ...
阅读全文
摘要:class Solution { public List postorderTraversal(TreeNode root) { Stack stack=new Stack(); List res=new ArrayList(); while(root!=null||!stack.isEmpty()) { ...
阅读全文
摘要:class Solution { public List preorderTraversal(TreeNode root) { Stack stack=new Stack(); List res=new ArrayList(); while(root!=null||!stack.isEmpty()) { ...
阅读全文
摘要: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; ...
阅读全文
摘要: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...
阅读全文
摘要:class Solution { public List wordBreak(String s, List wordDict) { Map> map=new HashMap>(); wordBreak(s, map, wordDict); return map.get(s); } private void wordBreak...
阅读全文
摘要: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...
阅读全文
摘要:public class Solution { public RandomListNode copyRandomList(RandomListNode head) { Map map=new HashMap(); RandomListNode p=new RandomListNode(0); p.next=head; Ran...
阅读全文
摘要:class Solution { public int singleNumber(int[] nums) { int res=0; for(int i=0;i>i)&1; res|=(sum%3)<<i; } return res; } }
阅读全文
摘要: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...
阅读全文
摘要:class Solution { public int canCompleteCircuit(int[] gas, int[] cost) { int total=0,cur=0,start=0; for(int i=0;i=0?start:-1; } }
阅读全文
摘要:public class Solution { public UndirectedGraphNode cloneGraph(UndirectedGraphNode node) { if(node==null) return null; Map map=new HashMap(); Queue que=new Link...
阅读全文
摘要: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++) ...
阅读全文
摘要:class Solution { public List> partition(String s) { List> res=new ArrayList>(); generatePartition(0,new ArrayList(),res,s); return res; } private void generatePart...
阅读全文
摘要: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...
阅读全文
摘要:class Solution { public int sumNumbers(TreeNode root) { return sumNumber("", root); } private int sumNumber(String str, TreeNode node){ if(node==null) return 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) ...
阅读全文
摘要:class Solution { public int ladderLength(String beginWord, String endWord, List wordList) { Set dict=new HashSet(wordList); if(!dict.contains(endWord)) return 0; ...
阅读全文
摘要:class Solution { public List> findLadders(String beginWord, String endWord, List wordList) { List> res=new ArrayList>(); Set dict=new HashSet(wordList); if(!dict.contains(...
阅读全文
摘要:class Solution { int maxPathSum; public int maxPathSum(TreeNode root) { maxPathSum=Integer.MIN_VALUE; seachPathSum(root); return maxPathSum; } private int seac...
阅读全文
摘要:压缩
阅读全文

浙公网安备 33010602011771号