Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 65a1314

Browse files
committed
Have implemented the program to find the complete arranging coins.
1 parent 1c72c08 commit 65a1314

File tree

3 files changed

+54
-12
lines changed

3 files changed

+54
-12
lines changed

.idea/workspace.xml

Lines changed: 13 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/com/raj/ArrangingCoins.java

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/*
2+
Arranging Coins
3+
Link: https://leetcode.com/problems/arranging-coins/
4+
5+
You have n coins and you want to build a staircase with these coins. The staircase consists of k rows where the ith row has exactly i coins. The last row of the staircase may be incomplete.
6+
7+
Given the integer n, return the number of complete rows of the staircase you will build.
8+
9+
Example 1:
10+
Input: n = 5
11+
Output: 2
12+
Explanation: Because the 3rd row is incomplete, we return 2.
13+
14+
Example 2:
15+
Input: n = 8
16+
Output: 3
17+
Explanation: Because the 4th row is incomplete, we return 3.
18+
*/
19+
package com.raj;
20+
21+
public class ArrangingCoins {
22+
public static void main(String[] args) {
23+
// Initialization.
24+
int n = 5;
25+
int incrementer = 1;
26+
27+
// Logic.
28+
while (n > 0) {
29+
n = n - incrementer;
30+
incrementer++;
31+
}
32+
incrementer--;
33+
if (n < 0) {
34+
incrementer--;
35+
}
36+
37+
// Display the result.
38+
System.out.println("incrementer = " + incrementer);
39+
}
40+
}

src/com/raj/ShortestDistanceToCharacter.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ The distance between two indices i and j is abs(i - j), where abs is the absolut
3030

3131
public class ShortestDistanceToCharacter {
3232
public static void main(String[] args) {
33+
// Initialization.
3334
String s = "loveleetcode";
3435
char f = 'e';
3536
int l = s.length();

0 commit comments

Comments
 (0)