- 博客(21)
- 收藏
- 关注
原创 leetcode 714 Best Time to Buy and Sell Stock with Transaction Fee
class Solution { public int maxProfit(int[] prices, int fee) { int n=prices.length; if(prices==null||n==0) return 0; int[] buy=new int[n]; int[] sell=new int[n];
2017-10-28 14:35:06 146
原创 leetcode 681 Next Closest Time
class Solution { int diff = Integer.MAX_VALUE; String result = ""; public String nextClosestTime(String time) { Set set = new HashSet<>(); //set是接口。不能实例化 set.add(Integ
2017-10-26 16:15:43 834
原创 Leetcode 551 Student Attendance Record I
class Solution { public boolean checkRecord(String s) { return !s.matches(".*LLL.*|.*A.*A.*"); }}
2017-10-25 15:03:02 274
原创 leetcode 557 Reverse Words in a String III
class Solution { public String reverseWords(String s) { String[] str=s.split(" ");//split() 方法用于把一个字符串分割成字符串数组。 for(int i=0;i<str.length;i++) str[i]=new StringBuilder(str[i]).rever
2017-10-22 13:02:18 256
原创 leetcode 606 Construct String from Binary Tree
class Solution { public String tree2str(TreeNode t) { if(t==null) return ""; String left = tree2str(t.left); String right = tree2str(t.right); if(left==""&
2017-10-22 12:27:55 177
原创 leetcode 657 Judge Route Circle
class Solution { public boolean judgeCircle(String moves) { int x=0,y=0; for(int i=0;i<moves.length();i++){ if(moves.charAt(i)=='U') x++; else if(moves.char
2017-10-21 12:56:24 247
原创 leetcode 680 Valid Palindrome II
class Solution { public boolean validPalindrome(String s) { int i=-1,n=s.length(); while(++i<--n) { if(s.charAt(i)!=s.charAt(n)) return isPal(s,i,n+1)||isPa
2017-10-21 12:23:13 226
原创 leetcode 686 Repeated String Match
class Solution { public int repeatedStringMatch(String A, String B) { int count = 0; StringBuilder sb = new StringBuilder(); while (sb.length() < B.length()) { sb.append(A);
2017-10-20 19:39:56 410
原创 leetcode 696 Count Binary Substrings
class Solution { public int countBinarySubstrings(String s) { int fir=0,sec=1,ans=0; for(int i=1;i<s.length();i++){ if(s.charAt(i)==s.charAt(i-1)) sec++; el
2017-10-18 15:58:51 393
原创 leetcode 561 Array Partition I
class Solution { public int arrayPairSum(int[] nums) { Arrays.sort(nums); int sum=0; for(int i=0;i<nums.length;i+=2) sum+=nums[i]; return sum; }}
2017-10-18 15:04:16 255
原创 leetcode 566 Reshape the Matrix
class Solution { public int[][] matrixReshape(int[][] nums, int r, int c) { int x=nums.length; int y=nums[0].length; if(x*y!=r*c) return nums; int[][] ans=new int[r
2017-10-17 21:20:57 211
原创 leetcode 581 Shortest Unsorted Continuous Subarray
class Solution { public int findUnsortedSubarray(int[] nums) { int n=nums.length,star=0,end=-1,max=nums[0],min=nums[n-1]; for(int i=1;i<n;i++){ max=Math.max(max,nums[i]
2017-10-16 13:26:20 181
原创 leet code 605 Can Place Flowers
class Solution { public boolean canPlaceFlowers(int[] flowerbed, int n) { int count=0; for(int i=0;i<flowerbed.length && count<n;i++){ if(flowerbed[i]==0 && (i == 0 ||
2017-10-15 20:06:09 201
原创 leetcode 628 Maximum Product of Three Numbers
class Solution { public int maximumProduct(int[] nums) { Arrays.sort(nums); //排序 int t=nums.length; return Math.max(nums[t-1]*nums[t-2]*nums[t-3],nums[0]*nums[1]*
2017-10-15 16:19:58 183
原创 leetcode 643 Maximum Average Subarray I
class Solution { public double findMaxAverage(int[] nums, int k) { int sum=0; for(int i=0;i<k;i++) sum+=nums[i]; int max=sum; for(int i=k;i<nums.length;i++)
2017-10-15 15:55:00 238
原创 leetcode 661 Image Smoother
class Solution { public int[][] imageSmoother(int[][] M) { if (M == null || M.length == 0) return new int[0][0]; int x=M.length; int y=M[0].length; int [][] result=
2017-10-12 16:19:08 345
原创 java的foreach简单理解
网上有关于foreach用法的详细介绍,小白并看不懂,自己简单理解了一下遍历数组时候的用法:package foreach;public class foreach { public static void main(String[] args) { // TODO Auto-generated method stub foreach exam = new foreach();
2017-10-12 15:32:11 522
原创 leetcode 665 Non-decreasing Array
class Solution { public boolean checkPossibility(int[] nums) { int t=0; for(int i=0;i<nums.length-1 && t<=1;i++){ if(nums[i]>nums[i+1]) { t++;
2017-10-11 16:03:05 184
原创 leetcode 674 Longest Continuous Increasing Subsequence
class Solution { public int findLengthOfLCIS(int[] nums) { int max_L=0,length=0; for(int i=0;i<nums.length;i++){ if(i==0||nums[i]>nums[i-1]) max_L=Math.max(max
2017-10-11 11:23:34 174
原创 leetcode 695 Max Area of Island
class Solution { public int maxAreaOfIsland(int[][] grid) { int max_air=0; for(int i=0;i<grid.length;i++){ for(int j=0;j<grid[0].length;j++){
2017-10-11 11:20:49 454
原创 java学习.二位数组的遍历
public class Array{ public static void main(String args[]) { int arr[][] = {{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}}; for (int x = 0; x < arr.length; x++) { for (int
2017-10-10 14:47:20 213
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人