当前位置: 首页 > news >正文

供应商系统单页网站排名优化

供应商系统,单页网站排名优化,新年免费ppt模板下载,动漫设计学校哪里好一、Nim 游戏 1、题目链接 点击跳转到题目位置 2、代码 class Solution {public boolean canWinNim(int n) {if(n % 4 0){return false;}return true;} }3、知识点 (1) 通过模拟来寻找 规律。 二、区域和检索 - 数组不可变 1、题目链接 点击跳转到题目位置 2、代码 …

一、Nim 游戏

1、题目链接

点击跳转到题目位置

2、代码

class Solution {public boolean canWinNim(int n) {if(n % 4 == 0){return false;}return true;}
}

3、知识点

(1) 通过模拟来寻找 规律。

二、区域和检索 - 数组不可变

1、题目链接

点击跳转到题目位置

2、代码

class NumArray {int[] sums;public NumArray(int[] nums) {int n = nums.length;sums = new int[n+1];for(int i = 0; i < n; ++i){sums[i + 1] = sums[i] + nums[i];}}public int sumRange(int left, int right) {return sums[right + 1] - sums[left];}
}/*** Your NumArray object will be instantiated and called as such:* NumArray obj = new NumArray(nums);* int param_1 = obj.sumRange(left,right);*/

3、知识点

(1) 使用前缀和来解决问题。

三、3 的幂

1、题目链接

点击跳转到题目位置

2、代码

class Solution {public boolean isPowerOfThree(int n) {if(n <= 0){return false;}while(n > 1){if(n % 3 == 0){n /= 3;} else{return false;}}   return true;}
}

3、知识点

(1) 模拟试除。

四、比特位计数

1、题目链接

点击跳转到题目位置

2、代码

class Solution {public int count(int n){int res = 0;while(n > 0){n &= (n - 1);++res;}return res;}public int[] countBits(int n) {int[] res = new int[n+1];for(int i = 0; i <= n; ++i){res[i] = count(i);}return res;}
}

3、知识点

(1) 位运算,知识点同2的幂。

五、4的幂

1、题目链接

点击跳转到题目位置

2、代码

class Solution {public boolean isPowerOfFour(int n) {return n > 0 && (n & (n - 1)) == 0 && n % 3 == 1;}
}

3、知识点

(1) 位运算,如何判断一个数是2的幂,4的幂除以3的余数等于1。

六、反转字符串

1、题目链接

点击跳转到题目位置

2、代码

class Solution {public void reverseString(char[] s) {int left = 0;int right = s.length - 1;while(left < right){char temp = s[left];s[left] = s[right];s[right] = temp;++left;--right;}}
}

3、知识点

(1) 双指针

七、反转字符串中的元音字母

1、题目链接

点击跳转到题目位置

2、代码

class Solution {public boolean judge(char ch){switch(ch){case 'a':case 'o':case 'i':case 'e':case 'u':case 'A':case 'E':case 'I':case 'O':case 'U':return true;}return false;}public String reverseVowels(String s) {int n = s.length();int left = 0;int right = n - 1;StringBuffer sb = new StringBuffer(s);while(left < right){while(left < n && judge(sb.charAt(left)) == false){++left;}while(right >= 0 && judge(sb.charAt(right)) == false){--right;}if(left > right){break;}char temp = sb.charAt(left);sb.setCharAt(left, sb.charAt(right));sb.setCharAt(right, temp);++left;--right;}  return sb.toString();}
}

3、知识点

(1) 字符串中进行遍历,交换两个字符。

(2) java中switch操作。

八、 两个数组的交集

1、题目链接

点击跳转到题目位置

2、代码

class Solution {public int[] getIntersection(Set<Integer> set1, Set<Integer> set2){if(set1.size() < set2.size()){return getIntersection(set2, set1);}Set<Integer> intersectionSet = new HashSet<Integer>();for(int num : set1){if(set2.contains(num)){intersectionSet.add(num);}}int []res = new int[intersectionSet.size()];int index = 0;for(int num : intersectionSet){res[index++] = num;} return res;}public int[] intersection(int[] nums1, int[] nums2) {Set<Integer> set1 = new HashSet<Integer>();Set<Integer> set2 = new HashSet<Integer>();for(int i = 0; i < nums1.length; ++i){set1.add(nums1[i]);} for(int i = 0; i < nums2.length; ++i){set2.add(nums2[i]);}return getIntersection(set1, set2);}
}

3、知识点

(1) java中的集合。

九、两个数组的交集 II

1、题目链接

点击跳转到题目位置

2、代码

class Solution {public int[] intersect(int[] nums1, int[] nums2) {int len1 = nums1.length;int len2 = nums2.length;int[] hash1 = new int[1005];int[] hash2 = new int[1005];int[] res = new int[Math.min(len1, len2)];for(int i = 0; i < len1; ++i){hash1[nums1[i]]++;}for(int i = 0; i < len2; ++i){hash2[nums2[i]]++;}int index = 0;for(int i = 0; i <= 1000; ++i){int num = Math.min(hash1[i], hash2[i]);while(num > 0){--num;res[index] = i;++index;}}return Arrays.copyOfRange(res, 0, index);}
}

3、知识点

(1) 哈希表解决。

十、有效的完全平方数

1、题目链接

点击跳转到题目位置

2、代码

class Solution {public boolean isPerfectSquare(int num) {if((int)Math.sqrt(num) * (int)Math.sqrt(num) != num){return false;}return true;}
}

3、知识点

(1) 利用**内置函数sqrt()**即可。

十一、猜数字大小

1、题目链接

点击跳转到题目位置

2、代码

/** * Forward declaration of guess API.* @param  num   your guess* @return 	     -1 if num is higher than the picked number*			      1 if num is lower than the picked number*               otherwise return 0* int guess(int num);*/public class Solution extends GuessGame {public int guessNumber(int n) {int left = 1;int right = n;while(left <= right){int mid = ((right - left) >> 1) + left;if(guess(mid) == -1){right = mid - 1;} else if(guess(mid) == 0){return mid;} else{left = mid + 1;}}return 0;}
}

3、知识点

(1) 二分搜索即可。

十二、赎金信

1、题目链接

点击跳转到题目位置

2、代码

class Solution {public boolean canConstruct(String ransomNote, String magazine) {int[] hash1 = new int[26];int[] hash2 = new int[26];for(int i = 0; i < ransomNote.length(); ++i){hash1[ransomNote.charAt(i) - 'a']++;}for(int i = 0; i < magazine.length(); ++i){hash2[magazine.charAt(i) - 'a']++;}for(int i = 0; i < 26; ++i){if(hash1[i] > hash2[i]){return false;}}return true;}
}

3、知识点

(1) 用数组来模拟哈希表

十三、字符串中的第一个唯一字符

1、题目链接

点击跳转到题目位置

2、代码

class Solution {public int firstUniqChar(String s) {int[] hash1 = new int[26];for(int i = 0; i < s.length(); ++i){hash1[s.charAt(i) - 'a']++;}for(int i = 0; i < s.length(); ++i){if(hash1[s.charAt(i) - 'a'] == 1){return i;}}return -1;}
}

3、知识点

(1) 哈希表来统计字符数量。

十四、找不同

1、题目链接

点击跳转到题目位置

2、代码

class Solution {public char findTheDifference(String s, String t) {int[] hash1 = new int[26];int[] hash2 = new int[26];for(int i = 0; i < s.length(); ++i){hash1[s.charAt(i) - 'a']++;}for(int i = 0; i < t.length(); ++i){hash2[t.charAt(i) - 'a']++;}for(int i = 0; i < 26; ++i){if(hash1[i] != hash2[i]){return (char)(i + 'a'); }}return ' ';}
}

3、知识点

(1) 哈希表统计字符串。

十五、判断子序列

1、题目链接

点击跳转到题目位置

2、代码

class Solution {public boolean isSubsequence(String s, String t) {int i = 0;int j = 0;int m = s.length();int n = t.length();while(i < m && j < n){if(s.charAt(i) == t.charAt(j)){++i;++j;} else{++j;}}if(i != m){return false;}return true;}
}

3、知识点

(1) 双指针解决问题。

http://www.yidumall.com/news/10848.html

相关文章:

  • 比价网站开发毕业论文成人本科报考官网
  • wordpress 主题编辑seo技术自学
  • 做网站的抬头怎么做口碑营销案例简短
  • 手机网站微信网站开发成都本地推广平台
  • 门户网站建设管理工作方案北京网站排名seo
  • 网站备案官网免费发布信息平台有哪些
  • 网站建设销售是做什么的网络广告的计费方式
  • go 是做网站的吗外贸推广方式
  • 广药网站建设试题在线一键生成网页
  • 江苏住房与城乡建设厅网站大学生网页设计主题
  • 佛山企业网站开发抖音关键词排名软件
  • 做网站设像素免费seo关键词优化排名
  • 网站域名备案系统云南网站建设百度
  • 做家居网站设计百度关键词价格排行榜
  • pc网站和app哪个容易做网络平台有哪些
  • php实验报告企业网站开发seo综合查询工具可以查看哪些数据
  • 凯里市企业建站公司山西太原网络推广
  • 怎样解析网站域名解析百度seo排名优化
  • 网站开发遇到的问题及解决方法seo自媒体培训
  • 织梦网站字体大小电商网站建设教程
  • 网站有哪些功能15个常见关键词
  • 用pdf怎么做电子书下载网站郑州热门网络推广免费咨询
  • 外国专门做魔兽世界邪恶补丁网站网站建设的意义和目的
  • 排版设计网站代理推广
  • 在网上做国际快递淘宝网站百度关键词搜索量查询
  • 上海360网站建设安卓aso
  • 青浦门户网站一站式海外推广平台
  • 开发一整个网站要多久小程序设计
  • 企业网站备案流程站长之家是干什么的
  • 细分网站关于网站推广