From fe1d0f4feddc2d6dd7cd27a21c4405929a720def Mon Sep 17 00:00:00 2001 From: 1170300619 <3469205806@qq.com> Date: Thu, 17 Sep 2020 15:42:29 +0800 Subject: [PATCH] 2020.9.17 --- ...\345\205\261\345\211\215\347\274\200.java" | 44 +++++++++++++++ ...\346\225\260\344\271\213\345\222\214.java" | 54 +++++++++++++++++++ 2 files changed, 98 insertions(+) create mode 100644 "14.\346\234\200\351\225\277\345\205\254\345\205\261\345\211\215\347\274\200.java" create mode 100644 "15.\344\270\211\346\225\260\344\271\213\345\222\214.java" diff --git "a/14.\346\234\200\351\225\277\345\205\254\345\205\261\345\211\215\347\274\200.java" "b/14.\346\234\200\351\225\277\345\205\254\345\205\261\345\211\215\347\274\200.java" new file mode 100644 index 0000000..a7c9405 --- /dev/null +++ "b/14.\346\234\200\351\225\277\345\205\254\345\205\261\345\211\215\347\274\200.java" @@ -0,0 +1,44 @@ +/* + * @lc app=leetcode.cn id=14 lang=java + * + * [14] 最长公共前缀 + */ + +// @lc code=start +class Solution { + public String longestCommonPrefix(String[] strs) { + // StringBuilder ans = new StringBuilder(); + if(strs.length == 1){ + return strs[0]; + } + if(strs.length == 0){ + return ""; + } + String index = strs[0]; + for(int i=1;i strs[i].length()){ + index = strs[i]; + } + } + int flag = 0; + while(index.length() > 0){ + for(int i = 0;i> threeSum(int[] nums) { + List> ans = new ArrayList<>(); + + if(nums == null || nums.length < 3){ + return ans; + } + + Arrays.sort(nums); + + if(nums[0]> 0){ + return ans; + } + int start,end = 0; + for(int i = 0;i 0 && (nums[i] == nums[i - 1])){ + continue; + } + start = i + 1; + end = nums.length -1; + while(start < end){ + if(nums[i] + nums[start] + nums[end] == 0){ + ans.add(new ArrayList<>(Arrays.asList(nums[i],nums[start],nums[end]))); + start++; + end--; + while(start < end && nums[start] == nums[start - 1]){ + start++; + } + while(start < end && nums[end] == nums[end + 1]){ + end--; + } + }else if(nums[i] + nums[start] + nums[end] < 0){ + start++; + }else if(nums[i] + nums[start] + nums[end] > 0){ + end--; + } + } + } + return ans; + } +} +// @lc code=end +