עבור לתוכן
View in the app

A better way to browse. Learn more.

HWzone

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

רקורסיה: מערך דו מימדי

Featured Replies

פורסם

למיטב ידיעתי לא, אבל יכול להיות שאני מפספס משהו.

שים לב שגם אם מותר לך לשנות את המערך, אתה יכול להחזיר אותו לקדמותו בסוף הפונקציה.

אתה מוזמן להעלות את הקוד הסופי שלך אם אתה רוצה הערות.

נערך על-ידי שניצל

פורסם
  • מחבר

בבקשה (ותודה...):

    public static int stain (char[][] mat, int row, int col)    {
int counter = 0;
int col_len = mat.length;
int row_len = mat[0].length;

if (row < 0 || col < 0 || row >= row_len || col >= col_len
|| mat[row][col] != 'x')
return 0;

else
{
if (mat[row][col] != '2')
{
counter += 1;
mat[row][col] = '2';
counter = counter + stain(mat, row + 1, col);
counter = counter + stain(mat, row - 1, col);
counter = counter + stain(mat, row, col - 1);
counter = counter + stain(mat, row + 1, col - 1);
counter = counter + stain(mat, row - 1, col - 1);
counter = counter + stain(mat, row, col + 1);
counter = counter + stain(mat, row + 1, col + 1);
counter = counter + stain(mat, row - 1, col + 1);
}



}

return counter;
}

פורסם

אחלה. אתה לא צריך את הבדיקה שהתא לא שווה 2, כי זה כבר "מוכל" בבדיקה שהוא שווה x.

פורסם
  • מחבר

תודה רבה.

ארכיון

דיון זה הועבר לארכיון ולא ניתן להוסיף בו תגובות חדשות.

דיונים חדשים

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.