LeetCode - Submission Details

int r,w;
void ser(char** s,int i,int j){
    if(i<0 || j <0 || i >= r || j >= w)return;
    if(s[i][j]==‘1‘){
        s[i][j]=0;
        ser(s,i-1,j);
        ser(s,i+1,j);
        ser(s,i,j-1);
        ser(s,i,j+1);
        return ;
    }
    else
        return ;
}

int numIslands(char** grid, int gridRowSize, int gridColSize) {
    int ans = 0;
    r = gridRowSize;
    w = gridColSize;
    for(int i = 0 ; i < gridRowSize; i ++){
        for(int j = 0 ; j < gridColSize; j ++){
            if(grid[i][j]==‘1‘){
                ser(grid,i,j);
                ans ++;
            }
        }
    }
    return ans;
}

时间: 2024-08-25 07:42:44

LeetCode - Submission Details的相关文章

Submission Details [leetcode] ---- inplace 线性时间 的两种思路

两种思路都利用了输入的数组A,若A中存在i,则给A[i]作为标记. 因为A中的n个元素存在>n和<=0的,所以第一个缺失的正整数一定在[1-n+1]之间. 第一种思路是将标记设为一个特定的数.因为改变数值会影响该位置原来存的值,所以需要在一个循环里依次处理所有"原来的值". 例如数组为{2,3,4,1}.对第一个数2,我们将位置(2-1)=1标记为-MAX_INT,数组变为{2,-MAX_INT,4,1},丢失了3,所以应记录下数组原来的值,并继续将位置(3-1)=2标记为

Submission Details [leetcode] 算法的改进

最先看到这一题,直觉的解法就是len从1到s1.size()-1,递归调用比较s1和s2长度为len的子串是否相等,以及剩余部分是否相等. 将s1分成s1[len + rest],分别比较s2[len + rest]和s2[rest + len] 代码如下: bool isScramble(string s1, string s2) { return find(s1, s2); } bool find(string s1, string s2) { if (s1.compare(s2) == 0

【leetcode】Submission Details

Given two sentences words1, words2 (each represented as an array of strings), and a list of similar word pairs pairs, determine if two sentences are similar. For example, words1 = ["great", "acting", "skills"] and words2 = [&

Submission Details

水水的动归 int min(int a,int b){ return a<b?a:b; } int minimumTotal(int **triangle, int numRows) { for(int i = numRows -2 ; i >= 0 ; i--){ for(int j = 0 ; j <= i ; j++){ triangle[i][j]+=min(triangle[i+1][j],triangle[i+1][j+1]); } } return triangle[0][

49.Submission Details java solutions

Given an array of strings, group anagrams together. For example, given: ["eat", "tea", "tan", "ate", "nat", "bat"], Return: [ ["ate", "eat","tea"], ["nat",

第一个leetcode题目: two sum

第一个leetcode,大概意思:在一个数组里,任意找两个数字,让它们的和等于一个给定目标值.要求:1.输出这两个数在数组的下标 2.保证第一个数的下标要小于第二个数的下标 做这个题,还是有一点点欣慰的地方就是:读完题,就有思路,而且能顺利编出来.(虽然因为那个小小的 return b 修改了好几次) public class Solution { public int[] twoSum(int[] nums, int target) { int[] b = new int[2]; for(in

leetcode 336. Palindrome Pairs

传送门 Given a list of unique words. Find all pairs of distinct indices (i, j) in the given list, so that the concatenation of the two words, i.e. words[i] + words[j] is a palindrome. Example 1:Given words = ["bat", "tab", "cat"

2. 从有序链表和数组中移出重复元素 Remove Duplicates

1. 链表 Remove Duplicates from Sorted List Given a sorted linked list, delete all duplicates such that each element appear only once. For example, Given 1->1->2, return 1->2. Given 1->1->2->3->3, return 1->2->3. 思路: 关于链表一般有两种实现方式:

餐厅电子管理系统

CP2011 Assignment Details, SP1 2014Imagine that you are programmer for a small independent software company. You have been given the task of implementing a prototype electronic restaurant management system as a proof-of-concept. The customer is a sma