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