
算法
xfgg
学无止境
展开
-
leetcode(六)
字符串中的第一个唯一字符 //利用哈希表来进行操作 class Solution { public int firstUniqChar(String s) { HashMap<Character, Integer> count = new HashMap<Character, Integer>(); int n = s.length(...原创 2020-02-04 18:38:51 · 105 阅读 · 0 评论 -
leetcode(五)
两个数组的交集 class Solution { public int[] intersect(int[] nums1, int[] nums2) { //直接进行排序,判断的非常快 Arrays.sort(nums1); Arrays.sort(nums2); int i = 0, j = 0, k = 0; while (i <...原创 2020-02-03 18:25:59 · 93 阅读 · 0 评论 -
leetcode(四)
从排序数组中删除重复项 class Solution { public int removeDuplicates(int[] nums) { //想法是两个指针,一个指定,一个遍历数组 if (nums.length == 0) return 0; int i = 0; for (int j = 1; j < nums.length;...原创 2020-02-02 18:14:04 · 106 阅读 · 0 评论 -
leetcode(三)
搜索二维矩阵II //暴力破解法 //搜索每一行查找要的元素 class Solution { public boolean searchMatrix(int[][] matrix, int target) { //保证每个数字只查询一遍,且瞬间确定哪一行或者哪一列 for (int i = 0; i < matrix.length; i++) { ...转载 2020-01-16 18:44:12 · 217 阅读 · 0 评论 -
leetcode(二)
解压缩编码列表 class Solution{ public int[] decompressRLElist(int[] nums){ List<Integer> list = new ArrayList<>(); for(int i = 0; i < nums.length / 2; i++) { fo...原创 2020-01-14 20:16:37 · 95 阅读 · 0 评论 -
leetcode(一)
反转字符串 void reverseString(char* s, int sSize){ int low = 0,high = sSize-1; char temp; while(low<=high) { temp = s[high]; s[high] = s[low]; s[low] = temp; ...原创 2020-01-13 16:16:58 · 83 阅读 · 0 评论