Skip to content

Commit 78371ab

Browse files
committed
readme
1 parent c8592f2 commit 78371ab

File tree

1 file changed

+36
-5
lines changed

1 file changed

+36
-5
lines changed

README.md

Lines changed: 36 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,36 @@
1414

1515
## `Today Update`
1616
### Math
17-
#### 7 Reverse Integer
18-
* [Github:#7 Reverse Integer](/Math/Math.Lib/ReverseIntegarSln.cs)
19-
* [CSDN:#7 Reverse Integer](http://blog.csdn.net/daigualu/article/details/72464418)
20-
* Tips:
21-
* an interesting way to check if happens overflow.
17+
#### 400 Nth Digit
18+
* [Github:#400 Nth Digit](/Math/Math.Lib/Nthdigit.cs)
19+
* [CSDN:#400 Nth Digit](http://blog.csdn.net/daigualu/article/details/72572244)
20+
* Tips:
21+
* careful to prevent overflowing for bas*digits, so declaring bas is long.
22+
```C#
23+
//for this issue, there are two different ways to decribe a number
24+
//1 element. this is our common way
25+
//2 Nth digit. this is a new way
26+
public int FindNthDigit(int n)
27+
{
28+
long bas = 9;
29+
int digits = 1, i = 0;
30+
//first: getting n which digit is in
31+
while (n > bas * digits) // prevent overflowing. Since bas is long, so result of bas*digits is auto imporved as long
32+
{
33+
n -= (int)(bas * (digits++)); //nth
34+
i += (int)bas; //number of pasted elements
35+
bas *= 10; //1 digit->9; 2 digits->90; 3 digits->900, ...
36+
}
37+
//second: Nth digit ->element
38+
//in all numbers containing digits, pasted numbers
39+
int pasted = (int)((n - 1) / digits);
40+
int element = pasted + i + 1;
41+
//third: once getting the element Nth digits stands,
42+
//(n-1)%digits of element is solution
43+
int nth = (n - 1) % digits;
44+
return element.ToString()[nth] - '0';
45+
}
46+
```
2247

2348
---
2449
---
@@ -156,6 +181,12 @@ Tags are following:
156181

157182
* [#507 Perfect Number](http://blog.csdn.net/daigualu/article/details/69233798)
158183

184+
#### 7 Reverse Integer
185+
* [Github:#7 Reverse Integer](/Math/Math.Lib/ReverseIntegarSln.cs)
186+
* [CSDN:#7 Reverse Integer](http://blog.csdn.net/daigualu/article/details/72464418)
187+
* Tips:
188+
* an interesting way to check if happens overflow.
189+
159190
#### 202 Happy Number
160191
* [Github:#202 Happy Number](/Math/Math.Lib/HappyNumber.cs)
161192
* [CSDN:#202 Happy Number](http://blog.csdn.net/daigualu/article/details/71433906)

0 commit comments

Comments
 (0)