摘要:
该题较为简单,合并排序即可。 public void merge(int[] nums1, int m, int[] nums2, int n) { List<Integer> res=new ArrayList<>(); for(int i=0;i<m;i++) res.add(nums1[i]) 阅读全文
摘要:
我们可以创建一个哈希表,对于每一个 x,我们首先查询哈希表中是否存在 target - x,然后将 x 插入到哈希表中,即可保证不会让 x 和自己匹配。 public int[] twoSum(int[] nums, int target) { Map<Integer,Integer> hs=new 阅读全文
摘要:
动态规划:每次算出以i结尾的连续子串的最大值,之后对dp[i]进行比较就可以得到最长子串。 public int maxSubArray(int[] nums) { int [] dp=new int [nums.length]; int max=nums[0]; dp[0]=nums[0]; fo 阅读全文