Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,28 +1,29 @@
# [3079.Find the Sum of Encrypted Integers][title]

> [!WARNING|style:flat]
> This question is temporarily unanswered if you have good ideas. Welcome to [Create Pull Request PR](https://github.com/kylesliu/awesome-golang-algorithm)

## Description
You are given an integer array `nums` containing **positive** integers. We define a function **encrypt** such that `encrypt(x)` replaces **every** digit in `x` with the **largest** digit in `x`. For example, `encrypt(523) = 555` and `encrypt(213) = 333`.

Return the **sum** of encrypted elements.

**Example 1:**

```
Input: a = "11", b = "1"
Output: "100"
```
Input: nums = [1,2,3]

## 题意
> ...
Output: 6

## 题解
Explanation: The encrypted elements are [1,2,3]. The sum of encrypted elements is 1 + 2 + 3 == 6.
```

**Example 2:**

### 思路1
> ...
Find the Sum of Encrypted Integers
```go
```
Input: nums = [10,21,31]

Output: 66

Explanation: The encrypted elements are [11,22,33]. The sum of encrypted elements is 11 + 22 + 33 == 66.
```

## 结语

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,24 @@
package Solution

func Solution(x bool) bool {
return x
func to(n int) int {
x, bits, mod := 0, 0, 0
for n > 0 {
mod = n % 10
n /= 10
x = max(x, mod)
bits++
}
base := 0
for ; bits > 0; bits-- {
base = base*10 + x
}
return base
}

func Solution(nums []int) int {
var ret int
for _, n := range nums {
ret += to(n)
}
return ret
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,11 @@ func TestSolution(t *testing.T) {
// 测试用例
cases := []struct {
name string
inputs bool
expect bool
inputs []int
expect int
}{
{"TestCase", true, true},
{"TestCase", true, true},
{"TestCase", false, false},
{"TestCase1", []int{1, 2, 3}, 6},
{"TestCase2", []int{10, 21, 31}, 66},
}

// 开始测试
Expand All @@ -30,10 +29,10 @@ func TestSolution(t *testing.T) {
}
}

// 压力测试
// 压力测试
func BenchmarkSolution(b *testing.B) {
}

// 使用案列
// 使用案列
func ExampleSolution() {
}
Loading