You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Roman numerals are represented by seven different symbols: `I`, `V`, `X`, `L`, `C`, `D` and `M`.
6
+
7
+
Symbol Value
8
+
I 1
9
+
V 5
10
+
X 10
11
+
L 50
12
+
C 100
13
+
D 500
14
+
M 1000
15
+
16
+
For example, `2` is written as `II` in Roman numeral, just two one's added together. `12` is written as `XII`, which is simply `X + II`. The number `27` is written as `XXVII`, which is `XX + V + II`.
17
+
18
+
Roman numerals are usually written largest to smallest from left to right. However, the numeral for four is not `IIII`. Instead, the number four is written as `IV`. Because the one is before the five we subtract it making four. The same principle applies to the number nine, which is written as `IX`. There are six instances where subtraction is used:
19
+
20
+
*`I` can be placed before `V` (5) and `X` (10) to make 4 and 9.
21
+
*`X` can be placed before `L` (50) and `C` (100) to make 40 and 90.
22
+
*`C` can be placed before `D` (500) and `M` (1000) to make 400 and 900.
23
+
24
+
Given an integer, convert it to a roman numeral.
25
+
26
+
**Example 1:**
27
+
28
+
**Input:** num = 3
29
+
30
+
**Output:** "III"
31
+
32
+
**Example 2:**
33
+
34
+
**Input:** num = 4
35
+
36
+
**Output:** "IV"
37
+
38
+
**Example 3:**
39
+
40
+
**Input:** num = 9
41
+
42
+
**Output:** "IX"
43
+
44
+
**Example 4:**
45
+
46
+
**Input:** num = 58
47
+
48
+
**Output:** "LVIII"
49
+
50
+
**Explanation:** L = 50, V = 5, III = 3.
51
+
52
+
**Example 5:**
53
+
54
+
**Input:** num = 1994
55
+
56
+
**Output:** "MCMXCIV"
57
+
58
+
**Explanation:** M = 1000, CM = 900, XC = 90 and IV = 4.
Roman numerals are represented by seven different symbols: `I`, `V`, `X`, `L`, `C`, `D` and `M`.
6
+
7
+
Symbol Value
8
+
I 1
9
+
V 5
10
+
X 10
11
+
L 50
12
+
C 100
13
+
D 500
14
+
M 1000
15
+
16
+
For example, `2` is written as `II` in Roman numeral, just two one's added together. `12` is written as `XII`, which is simply `X + II`. The number `27` is written as `XXVII`, which is `XX + V + II`.
17
+
18
+
Roman numerals are usually written largest to smallest from left to right. However, the numeral for four is not `IIII`. Instead, the number four is written as `IV`. Because the one is before the five we subtract it making four. The same principle applies to the number nine, which is written as `IX`. There are six instances where subtraction is used:
19
+
20
+
*`I` can be placed before `V` (5) and `X` (10) to make 4 and 9.
21
+
*`X` can be placed before `L` (50) and `C` (100) to make 40 and 90.
22
+
*`C` can be placed before `D` (500) and `M` (1000) to make 400 and 900.
23
+
24
+
Given a roman numeral, convert it to an integer.
25
+
26
+
**Example 1:**
27
+
28
+
**Input:** s = "III"
29
+
30
+
**Output:** 3
31
+
32
+
**Example 2:**
33
+
34
+
**Input:** s = "IV"
35
+
36
+
**Output:** 4
37
+
38
+
**Example 3:**
39
+
40
+
**Input:** s = "IX"
41
+
42
+
**Output:** 9
43
+
44
+
**Example 4:**
45
+
46
+
**Input:** s = "LVIII"
47
+
48
+
**Output:** 58
49
+
50
+
**Explanation:** L = 50, V= 5, III = 3.
51
+
52
+
**Example 5:**
53
+
54
+
**Input:** s = "MCMXCIV"
55
+
56
+
**Output:** 1994
57
+
58
+
**Explanation:** M = 1000, CM = 900, XC = 90 and IV = 4.
59
+
60
+
**Constraints:**
61
+
62
+
*`1 <= s.length <= 15`
63
+
*`s` contains only the characters `('I', 'V', 'X', 'L', 'C', 'D', 'M')`.
64
+
* It is **guaranteed** that `s` is a valid roman numeral in the range `[1, 3999]`.
Given an integer array `nums` sorted in **non-decreasing order**, remove the duplicates [**in-place**](https://en.wikipedia.org/wiki/In-place_algorithm) such that each unique element appears only **once**. The **relative order** of the elements should be kept the **same**.
6
+
7
+
Since it is impossible to change the length of the array in some languages, you must instead have the result be placed in the **first part** of the array `nums`. More formally, if there are `k` elements after removing the duplicates, then the first `k` elements of `nums` should hold the final result. It does not matter what you leave beyond the first `k` elements.
8
+
9
+
Return `k`_after placing the final result in the first_`k`_slots of_`nums`.
10
+
11
+
Do **not** allocate extra space for another array. You must do this by **modifying the input array [in-place](https://en.wikipedia.org/wiki/In-place_algorithm)** with O(1) extra memory.
12
+
13
+
**Custom Judge:**
14
+
15
+
The judge will test your solution with the following code:
16
+
17
+
int[] nums = [...]; // Input array
18
+
int[] expectedNums = [...]; // The expected answer with correct length
19
+
20
+
int k = removeDuplicates(nums); // Calls your implementation
21
+
22
+
assert k == expectedNums.length;
23
+
for (int i = 0; i < k; i++) {
24
+
assert nums[i] == expectedNums[i];
25
+
}
26
+
27
+
If all assertions pass, then your solution will be **accepted**.
28
+
29
+
**Example 1:**
30
+
31
+
**Input:** nums = [1,1,2]
32
+
33
+
**Output:** 2, nums = [1,2,\_]
34
+
35
+
**Explanation:** Your function should return k = 2, with the first two elements of nums being 1 and 2 respectively. It does not matter what you leave beyond the returned k (hence they are underscores).
36
+
37
+
**Example 2:**
38
+
39
+
**Input:** nums = [0,0,1,1,1,2,2,3,3,4]
40
+
41
+
**Output:** 5, nums = [0,1,2,3,4,\_,\_,\_,\_,\_]
42
+
43
+
**Explanation:** Your function should return k = 5, with the first five elements of nums being 0, 1, 2, 3, and 4 respectively. It does not matter what you leave beyond the returned k (hence they are underscores).
0 commit comments