do first question(triangel)
This commit is contained in:
Generated
+1
-1
@@ -1,6 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="$PROJECT_DIR$" vcs="Git" />
|
||||
<mapping directory="" vcs="Git" />
|
||||
</component>
|
||||
</project>
|
||||
@@ -20,8 +20,21 @@ public class MainExercises
|
||||
*/
|
||||
public char[][] generateTriangle(int n) {
|
||||
|
||||
// todo
|
||||
return null;
|
||||
char[][] triangle = new char[n][];
|
||||
|
||||
for(int i = 0 ; i < n ; i++){
|
||||
triangle[i] = new char[i+1];
|
||||
for(int j = 0 ; j < i+1 ; j++){
|
||||
if(i == 0 || j == 0 || i== j || i == n-1 ){
|
||||
triangle[i][j] = '*';
|
||||
}
|
||||
else{
|
||||
triangle[i][j] = ' ';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return triangle;
|
||||
|
||||
}
|
||||
|
||||
@@ -57,8 +70,9 @@ public class MainExercises
|
||||
- Number of rows: matrix.length
|
||||
- Number of columns: matrix[0].length (if rectangular)
|
||||
*/
|
||||
|
||||
public int[] spiralTraversal(int[][] matrix) {
|
||||
// todo
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user