ICode9

精准搜索请尝试: 精确搜索
  • [LeetCode] 283. Move Zeroes ☆(移动0到最后)2019-06-28 17:04:05

    描述 给定一个数组nums,写一个函数,将数组中所有的0挪到数组的末尾,维持其他所有非0元素的相对位置。 举例: nums = [0, 1, 0, 3, 12],  函数运行后结果为[1, 3, 12, 0, 0] 解析 快慢指针,慢指针指向第一个0,快指针指向第一个非0. 代码 public static void main(String[] args) {

  • 【LeetCode】19.Array and String — Move Zeroes 移动零2019-06-17 09:43:42

    Given an array nums, write a function to move all 0's to the end of it while maintaining the relative order of the non-zero elements. Example: Input: [0,1,0,3,12]Output: [1,3,12,0,0] Note:1.You must do this in-place without making a copy of the array

  • leetcode 73. Set Matrix Zeroes2019-05-25 22:41:24

    73. Set Matrix Zeroes 题目要求是二维数组中出现0的地方所在行和所在列全变成0。 题目的关键是O(1)的时间复杂度,也就是在原地做。 思路:将第一行、第一列,除了(0,0)这个点的其他所有点用来记录这一行或者这一列是否出现0。 具体做法:先判断第一行第一列本身是否有0,用两个变量保存。然

  • leetcode 73. Set Matrix Zeroes (medium)2019-04-07 14:52:54

    为了使用常数空间大小,将矩阵的第一行、第一列用来记录是否当前行、列需要全部置为0 class Solution { public: void setZeroes(vector<vector<int>> &matrix) { size_t m = matrix.size(); size_t n = matrix[0].size(); bool row_zero = false; bool col_zero =

  • leetcode 172. Factorial Trailing Zeroes求后面0的个数2019-03-02 16:49:27

    Given an integer n, return the number of trailing zeroes in n!. Example 1: Input: 3 Output: 0 Explanation: 3! = 6, no trailing zero. Example 2: Input: 5 Output: 1 Explanation: 5! = 120, one trailing zero. 题目链接:https://leetcode.com/problems/factoria

  • 474. Ones and Zeroes2019-02-26 16:52:03

    在计算机界中,我们总是追求用有限的资源获取最大的收益。 现在,假设你分别支配着 m 个 0 和 n 个 1。另外,还有一个仅包含 0 和 1 字符串的数组。 你的任务是使用给定的 m 个 0 和 n 个 1 ,找到能拼出存在于数组中的字符串的最大数量。每个 0 和 1 至多被使

  • LeetCode-73-Set Matrix Zeroes2019-01-31 20:39:45

    算法描述: Given a m x n matrix, if an element is 0, set its entire row and column to 0. Do it in-place. Example 1: Input: [   [1,1,1],   [1,0,1],   [1,1,1] ] Output: [   [1,0,1],   [0,0,0],   [1,0,1] ] Example 2: Input: [   [0,1,2,0],   [3,4,5,

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有