本人只会python,学算法遇阻。发现市面上几乎都是C,C++,JAVA的算法。求大侠指教,这几段代码是什么语言。其实把慕课网的相关视频都看一些差不多也知道了,想节省时间,就只有请教各位了。谢谢!!!public int[] twoSum(int[] nums, int target) { for (int i = 0; i < nums.length; i++) { for (int j = i + 1; j < nums.length; j++) { if (nums[j] == target - nums) { return new int[] { i, j }; } } } throw new IllegalArgumentException("No two sum solution");}public int[] twoSum(int[] nums, int target) { Map map = new HashMap(); for (int i = 0; i < nums.length; i++) { map.put(nums, i); } for (int i = 0; i < nums.length; i++) { int complement = target - nums; if (map.containsKey(complement) && map.get(complement) != i) { return new int[] { i, map.get(complement) }; } } throw new IllegalArgumentException("No two sum solution");} |