摘要:
题目链接 暴力 暴力写法直接循环遍历二位数组,查找该值是否存在 时间复杂度为:O(nm) class Solution { public boolean findNumberIn2DArray(int[][] matrix, int target) { int n = matrix.length; 阅读全文
摘要:
题目链接 暴力 直接利用双重循环找到当前值和数组中另一个值是否相加等于target 时间复杂度O(n2) class Solution { public: vector<int> twoSum(vector<int>& nums, int target) { for(int i = 0; i < n 阅读全文
摘要:
原题链接 分析 因为我们知道使用位运算符进行计算的时候就是使用的二进制位,所以可以直接行移位操作,然后判定有多少个1 public class Solution { // you need to treat n as an unsigned value public int hammingWeigh 阅读全文
摘要:
原题链接 分析 有题目可以知道找的是数组中的最小值,最容易想到的方法应该就是直接遍历数组,使用一个变量保存数组中的最小值 class Solution { public int minArray(int[] numbers) { if(numbers.length == 0) return 0; i 阅读全文