两数之和

class Solution {
    public int[] twoSum(int[] nums, int target) {
        StringBuilder sb = new StringBuilder();
        for(int a:nums){
            sb.append(a+"");
        }
        String s = sb.toString();
        for(int i =0 ;i<nums.length;i++){
            int tmp = target - nums[i];
            if(s.contains(tmp+"")){
                for(int j=0;j<nums.length;j++){
                    if(nums[j]==tmp){
                        return new int[]{i,j};
                    }
                }
            }
        }
        return null;
    }
}

 

posted @ 2020-12-01 13:46  fleam  阅读(78)  评论(0编辑  收藏  举报