File tree Expand file tree Collapse file tree 3 files changed +63
-0
lines changed Expand file tree Collapse file tree 3 files changed +63
-0
lines changed Original file line number Diff line number Diff line change 1+ //
2+ // Contains_Duplicate.swift
3+ // Algorithm
4+ //
5+ // Created by 안세훈 on 3/31/25.
6+ //
7+
8+ import Foundation
9+
10+ class Solution {
11+ func containsDuplicate( _ nums: [ Int ] ) -> Bool {
12+ return nums. count != Set ( nums) . count
13+ //Set : 중복된 값을 갖지 않음.
14+ //문제로 주어진 배열의 개수와 중복을 갖지않는 Set연산의 개수의 차이 비교
15+ //비교 후 다르다면 true 같다면 false
16+ }
17+ }
Original file line number Diff line number Diff line change 1+ //
2+ // Top_K_Frequent_Elements .swift
3+ // Algorithm
4+ //
5+ // Created by 안세훈 on 3/31/25.
6+ //
7+
8+ class Solution {
9+ func topKFrequent( _ nums: [ Int ] , _ k: Int ) -> [ Int ] {
10+ var dic : [ Int : Int ] = [ : ]
11+
12+ for i in nums {
13+ dic [ i] = dic [ i , default : 0 ] + 1
14+ }
15+
16+ var sortarray = dic. sorted { $0. value > $1. value}
17+ var answer : [ Int ] = [ ]
18+
19+ for i in 0 ..< k{
20+ answer. append ( sortarray [ i] . key)
21+ }
22+ print ( sortarray)
23+ print ( answer)
24+ return answer
25+ }
26+ }
Original file line number Diff line number Diff line change 1+ //
2+ // Two_Sum.swift
3+ // Algorithm
4+ //
5+ // Created by 안세훈 on 3/31/25.
6+ //
7+
8+ class Solution {
9+ func twoSum( _ nums: [ Int ] , _ target: Int ) -> [ Int ] {
10+ for i in 0 ... nums. count- 1 {
11+ for j in i+ 1 ... nums. count- 1 {
12+ if nums [ i] + nums[ j] == target{
13+ return [ i, j]
14+ }
15+ }
16+ }
17+ return [ ]
18+ }
19+ //i번째 인덱스의 값과, j번째 인덱스의 값이 target과 같으면 i,j를 리턴
20+ }
You can’t perform that action at this time.
0 commit comments